Task:
use a while loop to calculate the sum of all numers from 1 to 1000.
So nachdem ich ein bisschen gegooglet habe kam ich zwar auf eine Lösung, doch die funktioniert nicht wie ich es will.
wo ist der fehler?
use a while loop to calculate the sum of all numers from 1 to 1000.
So nachdem ich ein bisschen gegooglet habe kam ich zwar auf eine Lösung, doch die funktioniert nicht wie ich es will.
wo ist der fehler?
Java:
public class Main
{
public static void main(String[] args)
{
int sum = 0;
int i = 1;
while (i <=1000)
{
sum = sum + i;
System.out.println(sum);
i++;
}
}
}