Page 215 - CA_Blue( J )_Class9
P. 215
You will get the following output:
Program 4 Write a program to print the sum of numbers from 1 to 1000.
1 class number_sum
2 {
3 public static void main(String args[])
4 {
5 int i = 1;
6 int sum = 0;
7 while (i <= 1000)
8 {
9 sum += i;
10 i++;
11 }
12 System.out.println("The sum of numbers from 1 to 1000 is " + sum);
13 }
14 }
You will get the following output:
Iterative Constructs in Java 213

