Here is the code that will help to get the largest number.
- import java.util.Scanner;
- class BigNum
- {
- public static void main(String args[])
- {
- int a, b, c, d;
- System.out.println("To get the largest among different numbers: ");
- System.out.println();
- System.out.println("Enter three integers: ");
- Scanner in = new Scanner(System.in);
- a = in.nextInt();
- b = in.nextInt();
- c = in.nextInt();
- d = in.nextInt();
- if ( a > b && a > c && a > d)
- System.out.println("1st number is largest.");
- else if ( b > a && b > c && b > d)
- System.out.println("2nd number is largest.");
- else if ( c > a && c > b && c > d)
- System.out.println("3rd number is largest.");
- else if ( d > a && d > b && d > c)
- System.out.println("4th number is largest.");
- else
- System.out.println("Entered numbers are not different.");
- }
- }
Thank you, keep learning and sharing.