+ 1
Use a while loop to calculate the sum of all numbers from 1 to 1000. Make it print only the sum, not the intermediate values.
public class Main { public static void main(String[] args) { int sum = 0; // Use a while loop to calculate the sum of 1 to 1000 System.out.println(sum); } }
6 odpowiedzi
+ 4
https://www.sololearn.com/learn/Java/2146/?ref=app
If you read the lesson about while loops it should be possible to solve your task by your own.
+ 3
public class Main
{
public static void main(String[] args)
{
int sum = 0;
int i=1;
// Use a while loop to calculate the sum of 1 to 1000
while(i <=1000)
{sum =sum+i;
i++;
}
System.out.println(sum);
}
}
0
I can't complete it