Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, Please help write program in JAVA that prints out the Multiplication Tabl

ID: 3838029 • 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 2

Explanation / Answer

import java.util.*;

public class HelloWorld{
static int[][] table;
public static void loadArray(int table[][],int x,int y){
int temp;
int initial=x;
temp=x;

for (int row = 0; row < table.length ; row++)
{   
for (int column = 0; column < table[row].length; column++)
{
table[row][column] = x*temp;
temp++;
}
x++;
temp=initial;
}

  
}
public static void printMultiplicationTable(int table[][],int x,int y){

for (int row = 0; row < table.length ; row++)
{
  
System.out.println();
for (int column = 0; column < table[row].length; column++)
{
  
System.out.printf("%2d ",table[row][column]);
}
  

}
  
  
}
public static void main(String []args){

int x,y,z;
Scanner cin=new Scanner(System.in);
System.out.println("Enter the first number x");
x=cin.nextInt();
System.out.println("Enter the first number y");
y=cin.nextInt();
if (x>y)
z=x-y+1;
else
z=y-x+1;
table = new int[z][z];
loadArray(table,x,y);
printMultiplicationTable(table,x,y);
}
}

Output:

sh-4.3$ java -Xmx128M -Xms16M HelloWorld                                                                                                                                        

Enter the first number x                                                                                                                                                        

4                                                                                                                                                                               

Enter the first number y                                                                                                                                                        

8                                                                                                                                                                               

                                                                                                                                                                                

16 20 24 28 32                                                                                                                                                                  

20 25 30 35 40                                                                                                                                                                  

24 30 36 42 48                                                                                                                                                                  

28 35 42 49 56                                                                                                                                                                  

32 40 48 56 64 sh-4.3$ ^C                                                                                                                                                       

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote