Translate

Friday, November 17, 2017

Sample Java Program: Find The Largest of a 3 numbers

This code shows in finding the largest number in a given  3 numbers.


import java.util.Scanner;import java.util.Scanner;
class largest_of_3_numbers  {
public static void main(String[] args) {


int x,y,z;


Scanner input = new Scanner(System.in);

System.out.println("Enter 3 Numbers");

System.out.println("Enter your 1st Number:");
x = input.nextInt();

System.out.println("Enter your 2nd Number:");

y = input.nextInt();

System.out.println("Enter your 3rd Number:");

z = input.nextInt();

if (x>y&&x>z)

{System.out.println("The 1st number is the largest!"); }
else if (y>x&&y>z)

{System.out.println("The 2nd number is the largest!"); }
else if (z>x&&z>y)

{System.out.println("The 3rd number is the largest!"); }
else { System.out.print("Entered number is not distinct."); }
}
}


Output Screen shows:

largest of 3 numbers

No comments:

Post a Comment