Hello, Please help write program in JAVA that prints out the Multiplication Tabl
ID: 3838034 • Letter: H
Question
Hello,
Please help write program in JAVA that prints out the Multiplication Table for a range of numbers (positive integers).
PROGRAM MUST DO THE FOLLOWING:
1) Prompt the user for a starting number: 'x'
2) Prompt the user for an ending number: 'y'
3) Print 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:
In Figure 1 below, the 5 x 5 array is loaded with the products for the times tables from 5 to 8
In Figure 2 below, the 2 x 2 array is loaded with the products for the times tables from 5 to 6
CA. C: WindowsAsystem320cmd.exe Enter the starting value Enter the ending value 4 16 20 24 28 32 5 20 25 30 35 40 6 24 30 36 42 48 28 35 42 49 56 8 32 40 48 56 64 Press any key to continue Figure 1 CA. C:Windowslsystem32lcmd.exe Enter the starting value Enter the ending value 5 6 5 25 30 6 30 36 Press any key to continue Figure 2Explanation / Answer
import java.io.*;
import java.lang.Math;
import java.util.Scanner;
public class Multiplication {
public static void loadArray(int table[ ][ ], int x, int y){
int i, j;
int size;
int a,b;
size = Math.abs(x-y);
for (i=0; i<=size; i++){
a = 4 + i;
for (j=0; j<=size; j++) {
b = 4 + j;
table[i][j] = a * b;
}
}
}
public static void printMultiplicationTable(int table[ ][ ], int x, int y){
int i,j;
System.out.print(" ");
for (i=x; i<=y; i++)
System.out.print(i + " ");
System.out.println("--------------------------------------");
for (i = x; i<=y; i++){
Sytem.out.print(x + " "+ "|");
for (j=0; j<=y; j++){
System.out.print(" " + table[i][j]);
}
System.out.println();
}
}
public static void main(String args[]){
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the starting value");
int start = keyboard.nextInt();
System.out.println("Enter the ending value");
int end = keyboard.nextInt();
int size = Math.abs(start - end);
int [][] table = new int [size][size];
loadArray(table, start, end);
printMultiplicationTable(table,start,end);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.