87.3k views
5 votes
IN JAVA

Using a for loop, write a program that prompts the user to input a positive integer. It should then print the multiplication table of that number.

Enter a positive integer: 5


Example output:

0 0 0 0 0 0 0 0 0 0 0

0 1 2 3 4 5 6 7 8 9 10

0 2 4 6 8 10 12 14 16 18 20

0 3 6 9 12 15 18 21 24 27 30

0 4 8 12 16 20 24 28 32 36 40

0 5 10 15 20 25 30 35 40 45 50

User Xecgr
by
5.2k points

1 Answer

0 votes

import java.util.Scanner;

public class JavaApplication67 {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.print("Enter a positive integer: ");

int num = scan.nextInt();

while (num < 0){

System.out.println("Please only enter positive numbers!");

num = scan.nextInt();

}

for (int i = 0; i <= 10; i++){

System.out.println(num*i);

}

}

}

This displays the given integer's multiplication table up to 10.

User Pranav Kapoor
by
5.3k points