Skip to content

Instantly share code, notes, and snippets.

@isauravmanitripathi
Last active March 30, 2019 18:45
Show Gist options
  • Save isauravmanitripathi/a18c01ddcab4dc683d0da3e524e6fbee to your computer and use it in GitHub Desktop.
Save isauravmanitripathi/a18c01ddcab4dc683d0da3e524e6fbee to your computer and use it in GitHub Desktop.
import java.util.Scanner;
/**
* Program to display a multiplication table where the user inputs the number of table to
* display
*
* made by: Saurav mani Tripathi
*
* published on github and medium under profile of Dammn
*/
public class MultiplicationTable {
private void MultiplicationTable(final int n) {
int counter = 1;
System.out.println("The" + n + "times table");
while (counter < 13) { //Display from 2 to 12
System.out.print(counter + "x" + n);
System.out.println("=" + counter * n);
counter = counter + 1;
}
}
private void doTable() {
Scanner in = new Scanner(System.in);
System.out.print("Which table(2-12)?");
final int x = in.nextInt();
if ((x < 2) || (x > 12)) {System.out.println("cannot display the table"); }
else { MultiplicationTable(x);}
}
public static void main (final String[] args) {
final MultiplicationTable object = new MultiplicationTable();
object.doTable();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment