-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.java
More file actions
34 lines (32 loc) · 1.04 KB
/
table.java
File metadata and controls
34 lines (32 loc) · 1.04 KB
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
30
31
32
33
34
import java.util.Scanner;
public class table {
public static void main(String[] args) {
printTable();
askAgain();
}
static void printTable() {
System.out.println("Enter the number to print its table : ");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.println("Table of " + num + " is :");
for (int i = 1; i <= 10; i++) {
System.out.println(num * i);
}
}
static void askAgain(){
System.out.println("Do you want to print another table - [Y(yes) | N(no)] : ");
Scanner Scan1 = new Scanner(System.in);
String choice = Scan1.nextLine();
if (choice.equals("y")||choice.equals("yes")||choice.equals("Y")||choice.equals("Yes")){
printTable();
askAgain();
}
else if (choice.equals("No")||choice.equals("N")||choice.equals("no")||choice.equals("n")){
return;
}
else{
System.out.println("Invalid choice");
askAgain();
}
}
}