This is the whole question:
1. Write a method:
+ inDescendingOrder(a:int, b:int, c:int): boolean
2. inDescendingOrder takes three parameters and returns true if a, b and c are in descending order and false otherwise.
3. Write a main method that asks the user for three numbers and then uses them to call inDescendingOrder() and reports if the initial 3 numbers were given in descending order or not.
A typical interaction might look like: Welcome to inDescendingOrder:
Enter the first number: 8
Enter the second number: 4
Enter the third number: 5
Those numbers were not entered in descending order. Where eight, four and five were the numbers entered by the user.
(When I try to run the code in the jGRASP, even if the numbers are not in descending order, it still says it's in descending order).
I want the code to be in if/ else statements and not arrays.
What I have tried:
import java.util.Scanner;
public class DescendingOrder{
public static void main(String[] args){
System.out.println("Welcome to inDecending Order");
int a = readInt("Enter first number: ");
int b = readInt("Enter second number: ");
int c = readInt("Enter third number: ");
inDescendingOrder(a,b,c);
if(true){
System.out.println("Those number were entered in decending order");
}else if(false){
System.out.println("Those number were not entered in decending order");
}else{
System.out.println("Error");
}
}
public static boolean inDescendingOrder(int a, int b, int c){
boolean flag;
if ((a<= b) && (a <= c)){
return flag= false;
}else if ((a<=b) && (a>=c)){
return flag= false;
}else if ((a >= b) && (a >= c)){
return flag = true;
}else{
return true;
}
}
public static int readInt(String prompt){
Scanner sc = new Scanner(System.in);
System.out.println(prompt);
return sc.nextInt();
}
}