-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathTable.java
29 lines (27 loc) · 847 Bytes
/
Table.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package src.college;
import java.io.*;
class Table {
public static void main(String[] args) {
Console c = System.console();
int n = Integer.parseInt(c.readLine("Enter the number to generate a table: "));
// Table with for loop
System.out.println("Table with for loop");
for (int i=1; i<=10; i++) {
System.out.println(n +" x "+ i+" = "+n*i);
}
// Table with while loop
System.out.println("Table with while loop");
int i = 1;
while(i<=10) {
System.out.println(n +" x "+ i+" = "+n*i);
i++;
}
//Table with do while loop
System.out.println("Table with do while loop");
i = 1;
do {
System.out.println(n +" x "+ i+" = "+n*i);
i++;
}while(i<=10);
}
}