
Return to Unit
Menu | Java Main Page |
MathBits.com |
Terms
of Use
Sample Fragments
using nested for loops
Nested FOR loops are often used to produce DESIGNS:
// The Isosceles Right Triangle (made with capital letters)
for (outer = 'F' ; outer >= 'A' ; outer--)
{
for (inner = 'A' ; inner <= outer; inner++)
{
System.out.print(inner);
}
System.out.println( );
} |
ABCDEF
ABCDE
ABCD
ABC
AB
A |
// Rectangle comprised of x's
for (rows = 0; rows < 4; rows++)
{
for (col = 0; col < 12; col++)
{
System.out.print("x") ;
}
System.out.println( );
} |
xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxx |
|

Return to Unit
Menu | Java Main Page |
MathBits.com |
Terms
of Use
|