Repeat until 0 Learn programming Java

Lesson:

Flow Control


Exercise:

Repeat until 0 31


Objetive:

Create a java program to ask the user for a number "x" and display 10*x. It must repeat until the user enters 0 (using "while").


Code:

import java.util.*;
public class Main
{
	public static void main()
	{
		int number;

		System.out.print("Enter a number: ");
		number = Integer.parseInt(new Scanner(System.in).nextLine());

		while (number != 0)
		{
			System.out.println(number * 10);

			System.out.print("Enter a number: ");
			number = Integer.parseInt(new Scanner(System.in).nextLine());
		}
	}
}