hi I'm trying to sort 3 numbers from lowest to highest that the user enters...ex ...2 , 4, 6. I have a problem with finding(calculating the middle) number.
this is what i have
//create a Scanner
Scanner scanner = new Scanner(System.in);
//Prompt the user to enter three floating-point numbers
System.out.println("Please enter three numbers:");
double num1 = scanner.nextDouble();
double num2 = scanner.nextDouble();
double num3 = scanner.nextDouble();
//Display inputs in sorted order
System.out.println("The inputs in sorted order are:");
//Find the minimum number input by the user
if ((num1 < num2) && (num1 < num3)) {
System.out.println(num1);
} else if ((num2 < num1) && (num2 < num3)) {
System.out.println(num2);
} else if ((num3 < num1) && (num3 < num2)) {
System.out.println(num3);
}
//Find the middle number input by the user
if ((num1 != num2) && (num1 != num3)) {
System.out.println(num1);
} else if ((num2 != num1) && (num2!= num3)) {
System.out.println(num2);
} else if ((num3 != num1) && (num3 <= num2)) {
System.out.println(num3);
}
// find the maximum number input by the user
if ((num1 > num2) && (num1 > num3)) {
System.out.println(num1);
} else if ((num2 > num1) && (num2 > num3)) {
System.out.println(num2);
} else if ((num3 > num1) && (num3 > num2)) {
System.out.println(num3);
}
}
}
display
Please enter three numbers:
2
4
6
The inputs in sorted order are:
2.0
2.0
6.0