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);
}
}
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);
}
}
Hi that’s easy. You do the calculation inside the loop but you put the print statement below it, outside the loop. Then when the loop is finished and it has added up the total, the loop exits and the line that says print is executed, just once.
I can not find it yet. Please write it down to me by the Java language script. Please write inside and outside the loop.