Skip to content

Commit f79adb2

Browse files
committed
feat: Print multiplication table of a number up to user-defined limit using while loop
🧠 Logic: - Takes two inputs from the user: the number to print the table for and the limit up to which it should print. - Uses a `while` loop starting from 1 up to `limit`. - Prints the format: number x i = product on each iteration. - Ensures scanner is closed to free resources. Signed-off-by: Somesh diwan <[email protected]>
1 parent d3f6d41 commit f79adb2

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
//Program to Print the Table of a Given Number Using while Loop
22

33

4-
//import java.util.Scanner;
5-
//
6-
//public class TableLoop {
7-
// public static void main(String[] args) {
8-
// Scanner sc = new Scanner(System.in);
9-
// System.out.print("Enter a number: ");
10-
// int number = sc.nextInt();
11-
// int i = 1; // Counter for the table
12-
//
13-
// while (i <= 10) {
14-
// System.out.println(number + " x " + i + " = " + (number * i));
15-
// i++;
16-
// }
17-
// }
18-
//}
4+
/*import java.util.Scanner;
5+
6+
public class TableLoop {
7+
public static void main(String[] args) {
8+
Scanner sc = new Scanner(System.in);
9+
System.out.print("Enter a number: ");
10+
int number = sc.nextInt();
11+
int i = 1; // Counter for the table
12+
13+
while (i <= 10) {
14+
System.out.println(number + " x " + i + " = " + (number * i));
15+
i++;
16+
}
17+
}
18+
}*/
1919

2020
import java.util.Scanner;
2121

2222
public class TableLoop {
2323
public static void main(String[] args) {
24-
Scanner sc = new Scanner(System.in); // Create scanner object to take user input
24+
Scanner sc = new Scanner(System.in); // Create a scanner object to take user input
2525

2626
// Ask for the number to print its multiplication table
2727

@@ -42,6 +42,6 @@ public static void main(String[] args) {
4242
System.out.println(number + " x " + i + " = " + (number * i)); // Print the multiplication
4343
i++; // Increment the counter
4444
}
45-
sc.close(); // Close the scanner to free resources
45+
sc.close();
4646
}
47-
}
47+
}

0 commit comments

Comments
 (0)