Java program to print Multiplication Table
1. Java program to print Multiplication Table(1 to 15) using for loop:
Program:
import java.io.*; import java.util.*; class Table { public static void main(String args[]) { for(int i=1;i<=15;i++) { for(int j=1;j<=10;j++) { System.out.print(+i+"*"+j+"="+(i*j)); System.out.print("\t"); } System.out.println("\n"); } } }
Output:
1*1=1 2*1=2 3*1=3 ................ 15*1=15 1*2=2 2*2=4 3*2=6 ................ 15*2=30 1*3=3 2*3=6 3*3=9 ............... 15*3=45 1*4=4 2*4=8 3*4=12 ............... 15*4=60 1*5=5 2*5=10 3*5=15 ............... 15*5=75 1*6=6 2*6=12 3*6=18 .............. 15*6=90 1*7=7 2*7=14 3*7=21 ............. 15*7=105 1*8=8 2*8=16 3*8=24 ............. 15*8=120 1*9=9 2*9=18 3*9=27 ............. 15*9=135 1*10=10 2*10=20 3*10=30 .......... 15*10=150
2. Java program to print Multiplication Table for any number using Scanner class:
Program:
import java.util.Scanner; public class Table { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter any number"); int n=sc.nextInt(); for(int i=1; i <= 10; i++) { System.out.println(n+" * "+i+" = "+n*i); } } }
Output:
Enter any number 5 5 * 1 = 5 5 * 2 = 10 5 * 3 = 15 5 * 4 = 20 5 * 5 = 25 5 * 6 = 30 5 * 7 = 35 5 * 8 = 40 5 * 9 = 45 5 * 10 = 50