4. Write a program (without using an array) that accepts three numbers from the user and prints "increasing" if the numbers are in increasing order, "decreasing" if the numbers are in decreasing order, and "Neither increasing or decreasing order" otherwise.
Example: Input first number: 1524
Input second number: 2345
Input third number: 3321
Expected Output :
Increasing order
import java.util.*;
class App {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Input first number: ");
int number1 = keyboard.nextInt();
System.out.print("Input second number: ");
int number2 = keyboard.nextInt();
System.out.print("Input third number: ");
int number3 = keyboard.nextInt();
if (number2 > number1 && number3 > number2) {
System.out.println("Increasing order");
} else if (number2 < number1 && number3 < number2) {
System.out.println("Decreasing order");
} else {
System.out.println("Neither increasing or decreasing order");
}
keyboard.close();
}
}
Comments
Leave a comment