Android IDE (AIDE) Support Forum

Doubt on java coding

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.

How to solve it.
Pls help me any one

int temp=1000, sum=0;
while (temp>0){sum+=temp; temp–;}
System.out.println("sum: "+sum);
:+1:

1 Like