Write a program which: 1. Prints out the Multiplication Table for a range of num
ID: 3828878 • Letter: W
Question
Write a program which:
1. Prints out the Multiplication Table for a range of numbers (positive integers). • Prompts the user for a starting number: say 'x' • Prompts the user for an ending number: say 'y' • Prints out the multiplication table of 'x' up to the number 'y'
SPECIFIC REQUIREMENTS
1. You must use the following method to load the array: public static void loadArray(int table[][], int x, int y) 2. You must use the following method to display the array: public static void printMultiplicationTable(int table[][], int x, int y) 3. You must load the table array with products of the factors. For example: the 5 x 5 array is loaded with the products for the times tables from 5 to 8
the 2 x 2 array is loaded with the products for the times tables from 5 to 6
1. No infinite loops, examples include: a. for(;;) b. while(1) c. while(true)
d. do{//code}while(1); 2. No break statements to exit loops
please write the code in the programming language java
Explanation / Answer
Please comment and explain the following part ==> " ........You must load the table array with products of the factors. For example: the 5 x 5 array is loaded with the products for the times tables from 5 to 8. the 2 x 2 array is loaded with the products for the times tables from 5 to 6...... "
public class MultiplicationTable {
public static int MAX_SIZE = 1000;
public static void loadArray(int[][] table, int x, int y) {
for (int i=0; i<=x; i++) {
for (int j=0; j<=y; j++) {
table[i][j] = i*j;
}
}
}
public static void printMultiplicationTable(int[][] table, int x, int y) {
for (int j=0; j<=y; j++) {
System.out.println(x + " x " + j + " = " +table[x][j]);
}
}
public static void main(String[] args) {
int[][] table = new int[MAX_SIZE][MAX_SIZE];
loadArray(table, 5,18);
printMultiplicationTable(table, 5, 18);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.