大家帮我看看这一提做的哪里不对?将while循环转换成for循环
public class Jjj{
public static void main(String[] args)
{
int i = 1;
int sum = 0;
while (sum < 5)
{
sum = sum + i;
i++;
}
System.out.println("这些数的和是:" + sum);
}
}
======================================
public class Jj
{
public static void main(String[] args)
{
int i = 1;
for (int sum = 0;sum < 5;i++)
{
sum = sum + i;
}
System.out.println("这些数的和是:" + sum);
}
}