// Example 1. The following program fragment finds the sum of the series:
// 1 squared + 2 squared +... + 100 squared. In the fragment, the variables,
// i and sum, must both be of type int.
public class SimpleForLoop1
{
public static void main (String[] args)
{
int sum = 0;
for (int i = 1 ; i <= 100 ; i++)
{
sum += i * i;
System.out.println (i + "\t" + sum);
}
System.out.println ("");
System.out.println ("The 'SimpleForLoop1' program has now terminated");
} // main method
} // SimpleForLoop1 class
No comments:
Post a Comment