62.4k views
18 votes
Click the above image

Ask the user to enter two numbers. The first number is for the multiplication table. The second number is the number of rows to display.

Use a for loop to print the table.

Click the above image Ask the user to enter two numbers. The first number is for the-example-1
User RaySF
by
5.8k points

1 Answer

7 votes

Answer:

Follows are the cdo0de to this question:

import java.util.*;//package

public class Table //defining class Table

{

public static void main(String[] asx)//main method

{

int x,y,i;//defining integer variables

Scanner bg=new Scanner(System.in);//creating Scanner class object

System.out.print("Enter first number: ");//print message

x=bg.nextInt();//input value

System.out.print("Enter Second number: ");//print message

y=bg.nextInt();//input value

for(i = 1; i <= y; i++)//defining for loop for print Table

{

System.out.printf("%d * %d = %d \\", x, i, x * i);//calculate and print table

}

}

}

Output:

Enter first number: 5

Enter Second number: 3

5 * 1 = 5

5 * 2 = 10

5 * 3 = 15

Explanation:

In the above code, three integer variable "x,y, and i" is declared, in which "x,y" variable is used to input value from the user end, and after input, the value the for loop is used, in which the second variable "y" count the rows, and "i, x" variable is used for calculates the multiplication of the table.

User Nick Van Brunt
by
5.4k points