Skip to content

Commit 7a92d27

Browse files
committed
init
1 parent fdbae11 commit 7a92d27

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import java.util.Scanner;
2+
3+
public class MultiplicationTableDemo {
4+
5+
public static void main(String[] args) {
6+
7+
// Prompt the user for number of rows and columns
8+
Scanner scanner = new Scanner(System.in);
9+
System.out.print("How many rows? ");
10+
int numRows = scanner.nextInt();
11+
12+
System.out.print("How many columns? ");
13+
int numCols = scanner.nextInt();
14+
15+
scanner.close();
16+
17+
// Initialize the array based on the rows and columns
18+
int[][] table = new int[numRows][numCols];
19+
20+
// Compute multiplication table values
21+
for (int row=0; row < numRows; row++) {
22+
23+
for (int col=0; col < numCols; col++) {
24+
// use (row+1) to give values 1 to numRows
25+
// similar thing for (col+1)
26+
table[row][col] = (row+1) * (col+1);
27+
}
28+
29+
}
30+
31+
System.out.println();
32+
33+
// Print out the results
34+
for (int row=0; row < numRows; row++) {
35+
36+
for (int col=0; col < numCols; col++) {
37+
System.out.print(table[row][col] + "\t");
38+
}
39+
System.out.println();
40+
41+
}
42+
}
43+
}
44+
45+
46+
47+
48+
49+
50+
51+
52+

0 commit comments

Comments
 (0)