Multiplication table with java

Java program to display multiplication table

We will learn how to create a multiplication table using loops. we can create multiplication table using for loop, while loop and do – while loop in C language.

Create multiplication table using for loop

we can create a multiplication table using for loop in Java language

import java.util.Scanner; public class Multiplication_Table< public static void main(String args[])< Scanner sc=new Scanner(System.in); int num=0; System.out.println("Enter the number: "); num=sc.nextInt(); for(int i=1; iEnter the number: 10 10x1=10 10x2=20 10x3=30 10x4=40 10x5=50 10x6=60 10x7=70 10x8=80 10x9=90 10x10=100

This multiplication is shown and explained using “x” mark

Читайте также:  Php break from foreach

In this program, the user can provide a needed range according to their preference and produced their all multiplication table according to the value provided

import java.util.Scanner; public class Multiplication_Table1< public static void main(String args[])< Scanner sc=new Scanner(System.in); int num,range; System.out.println("Enter the number: "); num=sc.nextInt(); System.out.println("Enter the range: "); range=sc.nextInt(); for(int i=1; iEnter the number: 15 Enetr the range: 12 15x1=15 15x2=30 15x3=45 15x4=60 15x5=75 15x6=90 15x7=105 15x8=120 15x9=135 15x10=150 15x11=165 15x12=180

Create multiplication table using while loop

we can create a multiplication table using while loop in Java language

import java.util.Scanner; public class Multiplication_Table2< public static void main(String args[])< Scanner sc=new Scanner(System.in); int num; System.out.println("Enter the number: "); num=sc.nextInt(); int i=1; while( i<=10;)< System.out.println(num+"x"+i+" EnlighterJSRAW" data-enlighter-language="null">Enter the number: 12 12*1=12 12*2=24 12*3=36 12*4=48 12*5=60 12*6=72 12*7=84 12*8=96 12*9=108 12*10=120

In this program, the user can provide a needed range according to their preference and produced their all multiplication table according to the value provided

import java.util.Scanner; public class Multiplication_Table3< public static void main(String args[])< Scanner sc=new Scanner(System.in); int num,range; System.out.println("Enter the number: "); num=sc.nextInt(); System.out.println("Enter the range: "); range=sc.nextInt(); int i=1; while(i<=range)< System.out.println(num+"x"+i+" EnlighterJSRAW" data-enlighter-language="null">Enter the number: 12 Enter the range 12 12X1=12 12X2=24 12X3=36 12X4=48 12X5=60 12X6=72 12X7=84 12X8=96 12X9=108 12X10=120 12X11=132 12X12=144

This multiplication is shown and explained using “x” mark

Create multiplication table using do-while loop

we can create a multiplication table using the do-while loop in Java language

import java.util.Scanner; public class Multiplication_Table4< public static void main(String args[])< Scanner sc=new Scanner(System.in); int num; System.out.println("Enter the number: "); num=sc.nextInt(); int i=1; do< System.out.println(num+"x"+i+" EnlighterJSRAW" data-enlighter-language="null">Enter the number: 15 15X1=15 15X2=30 15X3=45 15X4=60 15X5=75 15X6=90 15X7=105 15X8=120 15X9=135 15X10=150 15X11=165 15X12=180

In this program, the user can provide a needed range according to their preference and produced their all multiplication table according to the value provided

import java.util.Scanner; public class Multiplication_Table5< public static void main(String args[])< Scanner sc=new Scanner(System.in); int num,range; System.out.println("Enter the number: "); num=sc.nextInt(); System.out.println("Enter the range: "); range=sc.nextInt(); int i=1; do< System.out.println(num+"x"+i+" EnlighterJSRAW" data-enlighter-language="null">Enter the number: 12 Enter the range: 11 12x1=12 12x2=24 12x3=36 12x4=48 12x5=60 12x6=72 12x7=84 12x8=96 12x9=108 12x10=120 12x11=132

Another form of the multiplication table

Multiplication table using nested for loop

public class Multiplication_Table6 < public static void main (String args[])< System.out.print("Multiplication table\n"); for(int i=1; iSystem.out.println(); > > >

When the above code is executed, it produces the following results:

Java program to display multiplication table

This multiplication table is shown in the form of the table

Multiplication table using nested while loop

public class Multiplication_Table7 < public static void main (String args[])< System.out.print("Multiplication table\n"); int i=1; while(i<=10)< int j=1; while(j<=10)< System.out.print(i*j+"\t"); j++; >i++; System.out.println(); > > >

When the above code is executed, it produces the following results:

Java program to display multiplication table

This multiplication table is shown in the form of the table

Multiplication table using nested do- while loop

public class Multiplication_Table8< public static void main (String args[])< System.out.print("Multiplication table\n"); int i=1; do< int j=1; do< System.out.print(i*j+"\t"); j++; >while(j<=10); i++; System.out.println(); >while(i <=10); >>

When the above code is executed, it produces the following results:

Java program to display multiplication table

This multiplication table is shown in the form of the table

Suggested for you

For loop in C language

For loop in Python language

Do-while loop in Java language

Do-while loop in C language

Источник

Java Program to Print Multiplication Table For Given Number

Twitter Facebook Google Pinterest

A quick example program to create multiplication table in java using simple for loop and while loops.

1. Overview

In this article, you'll learn how to generate and print multiplication table in java for a given number. This can be done using for loop and while or do while loops.

2. Generate Multiplication Table Using For Loop

package com.javaprogramto.programs; public class MultiplicationTableForLoop < public static void main(String[] args) < int tableNumber = 10; System.out.println("Generating the table 10"); // generating table 10 for (int i = 1; i // generating the 20 table. System.out.println("\nGenerating the table 20"); int anotherTableNumber = 20; for (int i = 1; i > >
Generating the table 10 10 * 1 = 10 10 * 2 = 20 10 * 3 = 30 10 * 4 = 40 10 * 5 = 50 10 * 6 = 60 10 * 7 = 70 10 * 8 = 80 10 * 9 = 90 10 * 10 = 100 Generating the table 20 20 * 1 = 20 20 * 2 = 40 20 * 3 = 60 20 * 4 = 80 20 * 5 = 100 20 * 6 = 120 20 * 7 = 140 20 * 8 = 160 20 * 9 = 180 20 * 10 = 200

3. Generate Multiplication Table Using While Loop

public class MultiplicationTableWhileLoop < public static void main(String[] args) < int tableNumber = 5; System.out.println("Generating the table 9"); int tableStartIndex = 1; int tableEndIndex = 10; // generating table 10 while (tableStartIndex // generating the 20 table. System.out.println("\nGenerating the table 18"); // resetting the start and end index tableStartIndex = 1; tableEndIndex = 10; int anotherTableNumber = 18; while (tableStartIndex > >
Generating the table 9 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 Generating the table 18 18 * 1 = 5 18 * 2 = 10 18 * 3 = 15 18 * 4 = 20 18 * 5 = 25 18 * 6 = 30 18 * 7 = 35 18 * 8 = 40 18 * 9 = 45 18 * 10 = 50

4. Conclusion

In this short article, you've seen the easy engineering program to print the multiplication table in java with the help of for and while loops.

Labels:

SHARE:

Twitter Facebook Google Pinterest

About Us

Java 8 Tutorial

  • Java 8 New Features
  • Java 8 Examples Programs Before and After Lambda
  • Java 8 Lambda Expressions (Complete Guide)
  • Java 8 Lambda Expressions Rules and Examples
  • Java 8 Accessing Variables from Lambda Expressions
  • Java 8 Method References
  • Java 8 Functional Interfaces
  • Java 8 - Base64
  • Java 8 Default and Static Methods In Interfaces
  • Java 8 Optional
  • Java 8 New Date Time API
  • Java 8 - Nashorn JavaScript

Java Threads Tutorial

Kotlin Conversions

Kotlin Programs

Java Conversions

  • Java 8 List To Map
  • Java 8 String To Date
  • Java 8 Array To List
  • Java 8 List To Array
  • Java 8 Any Primitive To String
  • Java 8 Iterable To Stream
  • Java 8 Stream To IntStream
  • String To Lowercase
  • InputStream To File
  • Primitive Array To List
  • Int To String Conversion
  • String To ArrayList

Java String API

  • charAt()
  • chars() - Java 9
  • codePointAt()
  • codePointCount()
  • codePoints() - Java 9
  • compareTo()
  • compareToIgnoreCase
  • concat()
  • contains()
  • contentEquals()
  • copyValueOf()
  • describeConstable() - Java 12
  • endsWith()
  • equals()
  • equalsIgnoreCase()
  • format()
  • getBytes()
  • getChars()
  • hashcode()
  • indent() - Java 12
  • indexOf()
  • intern()
  • isBlank() - java 11
  • isEmpty()
  • join()
  • lastIndexOf()
  • length()
  • lines()
  • matches()
  • offsetByCodePoints()
  • regionMatches()
  • repeat()
  • replaceFirst()
  • replace()
  • replaceAll()
  • resolveConstantDesc()
  • split()
  • strip(), stripLeading(), stripTrailing()
  • substring()
  • toCharArray()
  • toLowerCase()
  • transform() - Java 12
  • valueOf()

Spring Boot

$show=Java%20Programs

$show=Kotlin

accumulo,1,ActiveMQ,2,Adsense,1,API,37,ArrayList,18,Arrays,24,Bean Creation,3,Bean Scopes,1,BiConsumer,1,Blogger Tips,1,Books,1,C Programming,1,Collection,8,Collections,37,Collector,1,Command Line,1,Comparator,1,Compile Errors,1,Configurations,7,Constants,1,Control Statements,8,Conversions,6,Core Java,149,Corona India,1,Create,2,CSS,1,Date,3,Date Time API,38,Dictionary,1,Difference,2,Download,1,Eclipse,3,Efficiently,1,Error,1,Errors,1,Exceptions,8,Fast,1,Files,17,Float,1,Font,1,Form,1,Freshers,1,Function,3,Functional Interface,2,Garbage Collector,1,Generics,4,Git,9,Grant,1,Grep,1,HashMap,2,HomeBrew,2,HTML,2,HttpClient,2,Immutable,1,Installation,1,Interview Questions,6,Iterate,2,Jackson API,3,Java,32,Java 10,1,Java 11,6,Java 12,5,Java 13,2,Java 14,2,Java 8,128,Java 8 Difference,2,Java 8 Stream Conversions,4,java 8 Stream Examples,12,Java 9,1,Java Conversions,14,Java Design Patterns,1,Java Files,1,Java Program,3,Java Programs,114,Java Spark,1,java.lang,4,java.util. function,1,JavaScript,1,jQuery,1,Kotlin,11,Kotlin Conversions,6,Kotlin Programs,10,Lambda,2,lang,29,Leap Year,1,live updates,1,LocalDate,1,Logging,1,Mac OS,3,Math,1,Matrix,6,Maven,1,Method References,1,Mockito,1,MongoDB,3,New Features,1,Operations,1,Optional,6,Oracle,5,Oracle 18C,1,Partition,1,Patterns,1,Programs,1,Property,1,Python,2,Quarkus,1,Read,1,Real Time,1,Recursion,2,Remove,2,Rest API,1,Schedules,1,Serialization,1,Servlet,2,Sort,1,Sorting Techniques,8,Spring,2,Spring Boot,23,Spring Email,1,Spring MVC,1,Streams,31,String,61,String Programs,28,String Revese,1,StringBuilder,1,Swing,1,System,1,Tags,1,Threads,11,Tomcat,1,Tomcat 8,1,Troubleshoot,26,Unix,3,Updates,3,util,5,While Loop,1,

A quick example program to create multiplication table in java using simple for loop and while loops.

Источник

Multiplication table in Java

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 program to print multiplication table

class MultiplicationTable
<
public static void main ( String args [ ] )
<
int n, c ;
System . out . println ( "Enter an integer to print it's multiplication table" ) ;
Scanner in = new Scanner ( System . in ) ;
n = in. nextInt ( ) ;
System . out . println ( "Multiplication table of " + n ) ;

for ( c = 1 ; c System . out . println ( n + "*" + c + " color: #339933;">+ ( n * c ) ) ;
>
>

Java program to print multiplication table output

Output of program:

Download Multiplication table program class file.

class Tables
<
public static void main ( String args [ ] )
<
int a, b, c, d ;

System . out . println ( "Enter range of numbers to print their multiplication tables" ) ;
Scanner in = new Scanner ( System . in ) ;

a = in. nextInt ( ) ;
b = in. nextInt ( ) ;

for ( c = a ; c System . out . println ( "Multiplication table of " + c ) ;

for ( d = 1 ; d System . out . println ( c + "*" + d + " color: #339933;">+ ( c * d ) ) ;
>
>
>
>

Источник

Program to Display multiplication table in Java

C program to Generate multiplication table

In this program, we are going to learn how to generate a multiplication table.

This is done using for loop , while loop , do-while loop , method and recursion in Java language

Code to print multiplication table in Java

Java code to print multiplication table using for loop

In this program, we will display the multiplication table using a for loop in Java language

Program to Display multiplication table in Java

//Java program to print multipication tabe //using for loop import java.util.Scanner; class Multipication_tabe< public static void main(String args[])< int num, i; Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("\nEnter the any number: "); num=scan.nextInt();//get input from the user for num for(i=1; i Print multiplication table

  • integer variable num and i are declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using Scanner class and store to the variable num
  • Create a for loop of i from 1 to 12 and increase the value of i after every iteration by 1
  • finally, the program displays the multiplication table usingSystem.out.print()function.

Java code to print multiplication table using while loop

In this program, we can display the multiplication table using a while loop in Java anguage. here, the while loop is functioning until the condition of the while loop is true

Program to Display multiplication table in Java

//Java program to print multipication tabe //using while loop import java.util.Scanner; class Multipication_tabe1< public static void main(String args[])< int num, i,j; Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("\nEnter the any number: "); num=scan.nextInt();//get input from the user for num i=1; while(i<=12)< System.out.println(num+" * "+i+" attachment_4709" aria-describedby="caption-attachment-4709" style="width: 462px" >print multiplication table

  • integer variable num and i are declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using Scanner class and store to the variable num
  • Create a while loop of i from 1 to 12 and increase the value of i after every iteration by 1
  • finally, the program displays the multiplication table usingSystem.out.print()function.

Java code to print multiplication table using do-while loop

In this program, we will display the multiplication table using a do-while loop in Java language. here, the while loop is functioning until the condition of the while loop is true

Program to Display multiplication table in Java

//Java program to print multipication tabe //using do-while loop import java.util.Scanner; class Multipication_tabe2< public static void main(String args[])< int num, i,j; Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("\nEnter the any number: "); num=scan.nextInt();//get input from the user for num i=1; do< System.out.println(num+" * "+i+" attachment_4711" aria-describedby="caption-attachment-4711" style="width: 416px" > print multiplication table

  • integer variable num and i are declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using Scanner class and store to the variable num
  • Create a do-while loop of i from 1 to 12 and increase the value of i after every iteration by 1
  • finally, the program displays the multiplication table usingSystem.out.print()function.

Java code to print multiplication table using method

In this program, we will display the multiplication table using a method in Java language.

Program to Display multiplication table in Java

//Java program to print multipication tabe //using method import java.util.Scanner; class Multipication_table_Method < public static void main(String args[])< int num, i,j; Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("\nEnter the any number: "); num=scan.nextInt();//get input from the user for num mulTable(num); >public static void mulTable(int num)

  • integer variable num and i are declared.
  • The program asks input from the user
  • Then the user enters the input values for num.
  • The program will read the input using Scanner class and store to the variable num
  • define a method named as mulTable(int num) for print multiplication table
  • Call the method to display multiplication table
  • Java code to print multiplication table using recursion

    In this program, we will display the multiplication table using a recursion in Java language.

    Recursion is a technique in Java programming where a method calls itself recursively. This technique is used to substitution the loops to execute the same code multiple time

    Program to Display multiplication table in Java

    //Java program to print multipication tabe //using recursive method import java.util.Scanner; class Multipication_table_Recursion < public static void main(String args[])< Scanner scan=new Scanner(System.in); //create a scanner object for input System.out.print("\nEnter the any number: "); int num=scan.nextInt();//get input from the user for num mulTable(num,1); >public static void mulTable(int num,int count)< if(count<=12)< System.out.println(num+" * "+count+" attachment_4738" aria-describedby="caption-attachment-4738" style="width: 550px" > Multiplication table in Java

    Suggested post

    Similar post

    Источник

    Оцените статью