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

Java coding help Write a program that will calculate a multiplication table for

ID: 3729193 • Letter: J

Question

Java coding help

Write a program that will calculate a multiplication table for a given number. The user will enter a number (it could be ANY number) and the number of lines they would like to see in the table.

For example, if the users enters a 5 for the multiplication number and 4 for the number of rows in the table, the result should be similar to the following:

5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20

Another example, if the users enters a 7 for the multiplication number and 3 for the number of rows in the table, the result should be similar to the following:

7 x 1 = 7
7 x 2 = 14
7 x 3 = 21

Note: You must use a loop to generate a table similar to the ones above

Explanation / Answer

MultiplicationTable.java

import java.util.Scanner;

public class MultiplicationTable {

public static void main(String[] args) {

//Declaring variables  

int mulNum,noOfRows;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Getting the input entered by the user

System.out.print("Enter the multiplication number :");

mulNum=sc.nextInt();

  

System.out.print("Enter no of rows :");

noOfRows=sc.nextInt();

  

//Displaying the table

for(int i=1;i<=noOfRows;i++)

{

System.out.println(mulNum+" X "+i+" = "+mulNum*i);

}

  

  

}

}

____________________

Output:

Enter the multiplication number :5
Enter no of rows :4
5 X 1 = 5
5 X 2 = 10
5 X 3 = 15
5 X 4 = 20

________________

Output#2:

Enter the multiplication number :7
Enter no of rows :3
7 X 1 = 7
7 X 2 = 14
7 X 3 = 21

______________Thank You

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