Create a Java console program that prompts a user to enter a number. The program
ID: 3817831 • Letter: C
Question
Create a Java console program that prompts a user to enter a number. The program uses the input value to calculate and list the products of two numbers up to the entered number. For instance, if a user has entered 3, the program calculates the products between two numbers (e.g., 1 times 1, 1 times 2, 1 times 3, 2 times 1, 2 times 2, 2 times 3, 3 times 1, 3 times 2, and 3 times 3), stores the products into a two-dimensional array, and list the multiplied numbers. The program then asks the user whether to continue or quit. If the user enters q, the program stops. If the user enters any other key but q, the program continues as shown in the following example. Use all your knowledge that you have learned in this course to complete the exam. Save your Java source code file as Exam03YourName.java (e.g., Exam03TomJones.java if your name is Tom Jones). If you have created multiple source code files, compress them in a zip file (name it as Exam03YourName.zip) and submit the compressed file. You should compile and test your source code file(s). If it works as required, submit your source code file (or compressed file) to the MSU Blackboard website by the end of April 14, 2017.Explanation / Answer
ProductOfTwoNos.java
import java.util.Scanner;
public class ProductOfTwoNos {
public static void main(String[] args) {
//Declaring variable
int number;
//Scanner object is used to get the inputs entered by the user
Scanner sc=new Scanner(System.in);
while(true)
{
//Getting the number entered by the user
System.out.print(" Enter a positive number :");
number=sc.nextInt();
System.out.print(" ");
for(int i=1;i<=number;i++)
{
System.out.print(i+" ");
}
System.out.println();
System.out.print(" ");
for(int i=1;i<=number;i++)
{
System.out.print("---"+" ");
}
System.out.println();
//Displaying the multiplication table
for(int i=1;i<=number;i++)
{
System.out.print(i+" ");
for(int j=1;j<=number;j++)
{
System.out.print(i*j+" ");
}
System.out.println();
}
System.out.println();
//Getting the character from the user 'Y' or 'y' or 'N' or 'n'
System.out.print("Do you want to continue(Y/N) ::");
char ch = sc.next(".").charAt(0);
if(ch=='Y'||ch=='y')
continue;
else
{
System.out.println(":: Program Exit ::");
break;
}
}
}
}
__________________
Output:
Enter a positive number :3
1 2 3
--- --- ---
1 1 2 3
2 2 4 6
3 3 6 9
Do you want to continue(Y/N) ::Y
Enter a positive number :4
1 2 3 4
--- --- --- ---
1 1 2 3 4
2 2 4 6 8
3 3 6 9 12
4 4 8 12 16
Do you want to continue(Y/N) ::N
:: Program Exit ::
______________Thank You
Please rate me well.If you area satisfied.