In this post you will learn how to print a table using while loop. As we know looping statements are used to repeat a statement until the specified the condition becomes false.
Now we will see the the example of this program;
class Table{
public static void main(String[] args) {
int a=10, b=1;
System.out.println("the table of "+a+"= ");
while(b<=10){
int c = a*b;
System.out.println(c);
b = b+1;
}
}
}
Output:
javac Table.java
java Table
the table of 10=
10*1=10
10*2=20
10*3=30
10*4=40
10*5=50
10*6=60
10*7=70
10*8=80
10*9=90
10*10=100
Now we will see the the example of this program;
class Table{
public static void main(String[] args) {
int a=10, b=1;
System.out.println("the table of "+a+"= ");
while(b<=10){
int c = a*b;
System.out.println(c);
b = b+1;
}
}
}
Output:
javac Table.java
java Table
the table of 10=
10*1=10
10*2=20
10*3=30
10*4=40
10*5=50
10*6=60
10*7=70
10*8=80
10*9=90
10*10=100
No comments:
Post a Comment