Loop Example: Squares
// Print out the squares of the numbers from 0 to 10.
public static void main(String[] args)
{
int i; // loop counter
i = 0;
// General idea: loop has printed squares of numbers
// from 0 to i-1.
while (i <= 10)
{
System.out.println(i*i);
i = i+1;
}
}
Previous slide
Next slide
Back to first slide
View graphic version