writa a Java program to print the largest of three numbers
Answers
Answered by
4
Java program to find the largest of three numbers and then print it. If the numbers are unequal then "numbers are not distinct" is printed. Comparison operator '>' is used to compare two numbers. To find the largest number out of a given numbers you can also use an array.
Java programming source code
import java.util.Scanner;
class Largest
{
public static void main(String args[])
{
int x, y, z;
System.out.println("Enter three integers");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
z = in.nextInt();
if (x > y && x > z)
System.out.println("First number is largest.");
else if (y > x && y > z)
System.out.println("Second number is largest.");
else if (z > x && z > y)
System.out.println("Third number is largest.");
else
System.out.println("The numbers are not distinct.");
}
}
Java programming source code
import java.util.Scanner;
class Largest
{
public static void main(String args[])
{
int x, y, z;
System.out.println("Enter three integers");
Scanner in = new Scanner(System.in);
x = in.nextInt();
y = in.nextInt();
z = in.nextInt();
if (x > y && x > z)
System.out.println("First number is largest.");
else if (y > x && y > z)
System.out.println("Second number is largest.");
else if (z > x && z > y)
System.out.println("Third number is largest.");
else
System.out.println("The numbers are not distinct.");
}
}
Similar questions