Exercise
Greatest Of Three Numbers
Objetive
Write a java program that prompts the user to enter three numbers and displays the greatest one.
Example Code
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int number1, number2, number3;
System.out.print("Enter the number 1:");
number1 = Integer.parseInt(new Scanner(System.in).nextLine());
System.out.print("Enter the number 2:");
number2 = Integer.parseInt(new Scanner(System.in).nextLine());
System.out.print("Enter the number 3:");
number3 = Integer.parseInt(new Scanner(System.in).nextLine());
if (number1 > number2 && number1 > number3)
{
System.out.println("The number 1 is greatest");
}
else if (number2 > number1 && number2 > number3)
{
System.out.println("The number 2 is greatest");
}
else if (number3 > number1 && number3 > number2)
{
System.out.println("The number 3 is greatest");
}
else
{
System.out.println("Numbers equals");
}
}
}