Skip to main content

Java program to print multiplication table


Java program to print multiplication table of a number entered by a user using a for loop. You can modify it for while or do while loop for practice. Using nested loops (a loop inside another loop), we can print tables of numbers between a given range say a to b, for example, if the input numbers are '3' and '6' then tables of '3', '4', '5' and '6' will be printed.

Java programming source code

  1. import java.util.Scanner;
  2.  
  3. class MultiplicationTable
  4. {
  5.   public static void main(String args[])
  6.   {
  7.     int n, c;
  8.     System.out.println("Enter an integer to print it's multiplication table");
  9.     Scanner in = new Scanner(System.in);
  10.     n = in.nextInt();
  11.     System.out.println("Multiplication table of " + n);
  12.  
  13.     for (c = 1; c <= 10; c++)
  14.       System.out.println(n + "*" + c + " = " + (n*c));
  15.   }
  16. }
Output of program:

Download Multiplication table program class file.
Code:
  1. import java.util.Scanner;
  2.  
  3. class Tables
  4. {
  5.   public static void main(String args[])
  6.   {
  7.     int a, b, c, d;
  8.  
  9.     System.out.println("Enter range of numbers to print their multiplication tables");
  10.     Scanner in = new Scanner(System.in);
  11.  
  12.     a = in.nextInt();
  13.     b = in.nextInt();
  14.  
  15.     for (c = a; c <= b; c++) {
  16.       System.out.println("Multiplication table of "+c);
  17.  
  18.       for (d = 1; d <= 10; d++) {
  19.         System.out.println(c+"*"+d+" = "+(c*d));
  20.       }
  21.     }
  22.   }
  23. }

Comments

Popular posts from this blog

Java program to print alphabets

Java program to print alphabets Java program to print alphabets on screen, i.e., a, b, c, ..., z; in lower case. Java source code class  Alphabets {     public   static   void  main ( String  args [ ] )     {        char  ch ;          for   ( ch  =   'a' ;  ch  <=   'z' ;  ch ++ )           System . out . println ( ch ) ;     } } You can easily modify the above java program to print alphabets in upper case. Download  Alphabets  program class file. Output of program: Printing alphabets using a while loop (Only the body of the main method is shown): char  c  =   'a' ;   while   ( c  <=   'z' )   {    System . out . println ( c ) ;   c ++; } Using a do while loop: char  c  =...

Use phone camera as a webcam without root in Hindi/urdu.