Write nested for loops that will display a multiplication table. Ask for an inte
ID: 3651898 • Letter: W
Question
Write nested for loops that will display amultiplication 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.
my code
import java.util.Scanner;
public class question24 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num = -1;
while(num <=0 || num > 10){
System.out.print("Enter an integer between 1 and 10:");
num = input.nextInt();
}
System.out.println();
for(int i = 1; i<=num; i++)
System.out.print(" "+i);
System.out.println(" ");
for(int row=1; row<=num; row++){
System.out.print(row + " ");
for (int tab=1; tab < row; tab++)
System.out.print(" ");
for(int col=row; col<=num; col++){
System.out.print(row*col + " ");
}//end inner for loop
System.out.println();
}//end outer for loop
}
}
Getting a weird diagonal output.. need help correcting my code to get proper run like below.
Proper output
java question3
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
3 6 9 12
4 8 12 16
Explanation / Answer
import java.util.Scanner; class question24 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int num; System.out.print("Enter an integer between 1 and 10:"); num = input.nextInt(); System.out.println(); if(num>0 && numRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.