Multiplication table (use while) Learn programming Java

Lesson:

Flow Control


Exercise:

Multiplication table (use while)


Objetive:

Write a java program that prompts the user to enter a number and displays its multiplication table using a 'while' loop.


Code:

import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		int num, multiplier = 1;

		System.out.print("Insert a number to multiply: ");
		num = Integer.parseInt(new Scanner(System.in).nextLine());

		while (multiplier <= 10)
		{
			System.out.printf("%1$s x %2$s = %3$s" + "\r\n", num, multiplier, num * multiplier);
			multiplier++;
		}
	}
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.