316,897 views
32 votes
32 votes
WAP to display greatest number of two imput number.​

User Brujoand
by
2.5k points

1 Answer

20 votes
20 votes

Answer:

This is a java program that helps display the largest number between two inputs.

Step-by-step explanation:

import java.util.Scanner;

public class LargestSmallest {

public static void main() {

Scanner in = new Scanner(System.in);

System.out.println("Enter first number: ");

int n1 = in.nextInt();

System.out.println("Enter second number: ");

int n2 = in.nextInt();

System.out.println("Enter third number: ");

int n3 = in.nextInt();

System.out.println("Choices: ");

System.out.println("1) Largest number");

System.out.println("2) Smallest number");

System.out.println("Enter number corresponding to your choice: ");

int choice = in.nextInt();

in.close();

switch(choice) {

case 1:

int largest = Math.max(n1, Math.max(n2, n3));

System.out.printf("Largest : %d", largest);

break;

case 2:

int smallest = Math.min(n1, Math.min(n2, n3));

System.out.printf("Smallest : %d", smallest);

break;

}

}

}

User Radek Simko
by
2.8k points