Write a program in java to print the tables of numbers up till 10. Ask the user
ID: 3638458 • Letter: W
Question
Write a program in java to print the tables of numbers up till 10. Ask the user up till whatnumber does he/she wants to print the tables for? Then print the tables starting from 1 until the user given number. One line should contain only one table. (30 points)
Example:
Output: How many numbers do you want to print the tables for?
User enters : 4
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9 1x10=10
2x1=2 2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=18 2x10=20
3x1=3 3x2=6 3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=27 3x10=30
4x1=4 4x2=8 4x3=12 4x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=36 4x10=40
(Hint: Use nested loops i.e., one loop inside the other. Two for loops should work
well
Explanation / Answer
Be sure to name the class multiplicationTables.
Hope this helps,
please rate!
import java.util.Scanner;
public class multiplicationTables {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numOfTables;
System.out.print("How many numbers do you want to print the table for?");
numOfTables = sc.nextInt();
System.out.println("User Entered: "+numOfTables);
for(int i = 1; i <= numOfTables; i++){
for(int j = 1; j<=10; j++){
System.out.print(i+"x"+j+"="+(i*j)+" ");
}
System.out.println("");
}
}
}
Related 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.