Java program that reads in three integers and prints "in order" if they are sorted in ascending or descending order, or "not in order" otherwise
Posted by Samath
Last Updated: February 12, 2021

Write a program that reads in three integers and prints "in order" if they are sorted in ascending or descending order, or "not in order" otherwise. For example,
     1 2 5 in order
     1 5 2 not in order
     5 2 1 in order
     1 2 2 in order

Code:

import java.util.Scanner;

public class Main
{
        public static void main(String[] args) {
        
        double num1;
        double num2;
        double num3;
	    
        Scanner input = new Scanner(System.in);
        
        System.out.println("Enter first number: ");
        num1 = input.nextDouble();
        
        System.out.println("Enter second number: ");
        num2 = input.nextDouble();
        
        System.out.println("Enter third number: ");
        num3 = input.nextDouble();
        
        if ((num1 <= num2  && num2 < num3) || (num1 < num2 && num2 <= num3) || (num1 > num2 && num2 >= num3) || (num1 >= num2 && num2 > num3))
        {
            System.out.println("In order");
        }
        else
        {
            System.out.println("Not in order");
        }
        input.close();
    }

}