Here we are going to write a program to display Java multiplication table for given number.
Input : Give Table Number : 7
Output :
7*1=7
7*2=14
7*3=21
7*4=28
7*5=35
7*6=42
7*7=49
7*8=56
7*9=63
7*10=70
[java]
package com.onlinetutorialspoint.javaprograms;
import java.util.Scanner;
public class MultiplicationTable {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Table number : ");
int number = sc.nextInt();
Logic logic = new Logic();
logic.set(number);
logic.table();
}
}
class Logic // Business Logic Class (BLC)
{
int n;
void set(int x) {
n = x;
}
void table() {
for (int i = 1; i <= 10; i++) {
int res = n * i;
System.out.println(n + "*" + i + "=" + res);
}
}
}
[/java]
Output :
Enter Table number : 7 7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49 7*8=56 7*9=63 7*10=70
Happy Learning 🙂