Write nested for loops that will display a multiplication table. Ask for an inte
ID: 3841718 • Letter: W
Question
Write nested for loops that will display a multiplication table. Ask for an integer from the user. Continue to re-prompt the user as long as the input is less than 1 or greater than 10. When you get valid input display a table similar to what is shown below. java question 3 Enter an integer between 1 and 10: -1 Enter an integer between 1 and 10:0 Enter an integer between 1 and 10: 4 1 2 3 4 2 4 6 8 5 6 9 12 4 8 12 16 java question3 Enter an integer between 1 and 10:7 1 2 3 4 5 6 7 2 4 6 8 10 12 14 3 6 9 12 15 18 21 4 8 12 16 20 24 28 5 10 15 20 25 30 35 6 12 18 24 30 36 42 7 14 21 28 35 42 49Explanation / Answer
import java.util.Scanner;
/**
*
* @author Sam
*/
public class NestedLoppTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
do {
System.out.println("Enter an integer between 1 and 10:");
n = sc.nextInt(); //accept a number
}while(n < 1 || n > 10); //validate entry
import java.util.Scanner;
for (int i = 1; i <= n; i++) { //outer loop
for (int j = 1; j <= n; j++) //inner loop
System.out.print(i*j + " "); //pring one data (data at ith colum and jth row is i*j)
System.out.println(); //go to next line
}
}
}
I tried my best ot keep the code as simple as possible. I have also commented the code to make your life easy. If incase you need more clarification, or facing any difficulty, please feel free to comment below. I shall be glad to help you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.