java Write a dowhile loop that prompts the user to enter a n
java
Write a do-while loop that prompts the user to enter a number between 1 and 10 until I successful input is collected. Use nested for loops to create an integer modulus table. Each entry in the table is the I remainder (modulus) of row/col. Rows and columns start at 1, not 0. Include row and column headings. Eg. n = 4 (4 times 4 table) two numbers from the user so that the table can be m times n (both 1Solution
Hi, Please find my implementation.
Please let me know in case of any issue.
import java.util.Scanner;
public class Program {
public static void main(String[] args) {
// Scanner Object to take user input
Scanner sc = new Scanner(System.in);
int num;
do{
// taking user input
System.out.print(\"Enter a integer value: \");
num = sc.nextInt();
}while(num < 1 || num > 10);
// 2
// printing column header
System.out.print(\" \");
for(int j=1; j<=4; j++)
System.out.print(j+\" \");
System.out.println();
for(int i=1; i<=4; i++){
System.out.print(i+\" \"); // row header
for(int j=1; j<=4; j++){
System.out.print((i%j)+\" \"); // printing column entry
}
System.out.println();
}
}
}
/*
Sample run:
Enter a integer value: 11
Enter a integer value: 5
1 2 3 4
1 0 1 1 1
2 0 0 2 2
3 0 1 0 3
4 0 0 1 0
*/

