-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask 1
30 lines (25 loc) · 1.07 KB
/
Task 1
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
import java.util.Scanner;
public class MultiplicationTable {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Step 1: Prompt the user to enter a number.
System.out.print("Enter a number: ");
int number = scanner.nextInt();
// Step 2: Prompt the user to enter another number to multiply with the first number.
System.out.print("Enter the range (up to 10) for multiplication table: ");
int range = scanner.nextInt();
// Step 3: Check if the range is above 10 and display an error message.
if (range > 10) {
System.out.println("Error: Range should be up to 10.");
} else {
// Step 6: Display the multiplication table
System.out.println("Multiplication Table of " + number + " (up to " + range + " multiply):");
for (int i = 1; i <= range; i++) {
int result = number * i;
System.out.println(number + " * " + i + " = " + result);
}
}
scanner.close();
}
}
#