Convert the following program from for loop to while loop.
class ArithmeticProgression
{
public static void main (String [] args)
{
int sum = 0;
for (int i = 1; i <= 1000; i++)
{
sum = sum + i;
System.out.println(Integer.toString(sum));
}
}
}
1
Expert's answer
2012-09-25T11:47:07-0400
class ArithmeticProgression { public static void main (String [] args) { int sum = 0; int i = 1; while(i <= 1000) { sum = sum + i; System.out.println(Integer.toString(sum)); i++; } } }
Comments
Leave a comment