public class TableOfSquares {
public static void main(String[] args) {
//for loop
System.out.println("----- Using for loop -----");
for(int a=1; a<=20;a++)
{
System.out.println();
System.out.print("Number: " + a + "\tSquare: " + (a*a) );
};
System.out.println(" " + "\n" + "\n");
//WHILE LOOP
int x=1;
System.out.println("----- Using while loop -----");
while(x<=20)
{
System.out.println();
System.out.print("Number: " + x + "\tSquare: " + (x*x) );
x++;
};
System.out.println(" " + "\n" + "\n");
//DO..WHILE LOOP
int a=1;
System.out.println("----- Using do..while loop -----");
do{System.out.println();
System.out.print("Number: " + a + "\tSquare: " + (a*a) );
a++;}
while (a<=20);
}
}
No comments:
Post a Comment