Search Logic Blocks

Saturday, January 25, 2020

Java: Let's practice - multiplication table

Problem : Write a Java program to print the multiplication table for user entered number.

Solution:

Class Multiplication (Multiplication.java)
import java.util.Scanner;

public class Multiplication {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the number for multiplication table");
        int num = sc.nextInt();
        int mul = 0;
        for(int i = 1; i <= 10; i++) {
            mul = num * i;
            System.out.println(num + "  *  " + i + "  =  " + mul);
        }
    }
}

Enter the number for multiplication table
19
19  *  1  =  19
19  *  2  =  38
19  *  3  =  57
19  *  4  =  76
19  *  5  =  95
19  *  6  =  114
19  *  7  =  133
19  *  8  =  152
19  *  9  =  171
19  *  10  =  190

No comments: