Sort three integers

The problem

In this java illustration, write a program that sorts three integers. The integers are entered from the input dialogs and stored in variables num1, num2, and num3, respectively. The program sorts the numbers so that num1 ... num2 ... num3.

Breaking it down

Create stream from ints by calling IntStream.of and passing in num1, num2 and num3 we will call sorted() which will order the integers in descending order. Next calling mapToObject will map each int to a string allowing us to collect and prepare to display to the user.

public static void main(String[] strings) {

    int num1;
    int num2;
    int num3;

    Scanner input = new Scanner(;
    System.out.print("Enter three Integers: ");
    num1 = input.nextInt();
    num2 = input.nextInt();
    num3 = input.nextInt();


    String prepareOutput = IntStream.of(num1, num2, num3).sorted()
            .mapToObj(String::valueOf).collect(Collectors.joining(" "));

    System.out.println("Sorted Numbers: " + prepareOutput);


Enter three Integers: 10
Sorted Numbers: 3 10 77