Good morning everyone. After spending a few hours pouring through the textbook I have been given for this assignment, I still cannot get my code to work. I am almost positive it is an issue with the nesting of my If-Else statements. I am also having an issue with the code, as it outputs the numbers added together. When I run the code and enter the numbers (10,5,20), my output is the following:
10
5 20
5
1020
20
510
The whole point of the program is to take the 3 numbers entered by the user(10,5,20), and output/sort them in ascending order (5,10,20).
If you can point me in the right direction without being too vague, I would greatly appreciate it. Thank you and have a wonderful day!
package sortthreeintegers; import java.util.Scanner; public class SortThreeIntegers { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter your first number: "); int num1 = input.nextInt(); System.out.print("Enter your second number: "); int num2 = input.nextInt(); System.out.print("Enter your third number: "); int num3 = input.nextInt(); //checking num1 if ((num1 < num2) && (num1 < num3)); { System.out.println("" + num1 + ""); if (num2 < num3) { System.out.println(num2 + " " + num3); } else System.out.println(num3 + "" + num2); } //checking num2 if ((num2 < num1) && (num2 < num3)); { System.out.println("" + num2 + ""); } if (num1 < num3) { System.out.println(num1 + "" + num3); } else { System.out.println(num3 + "" + num1); } //checking num3 if ((num3 < num1) && (num3 < num2)); { System.out.println("" + num3 + ""); } if (num1 < num2) { System.out.println(num1 + "" + num2); } else { System.out.println(num2 + "" + num1); } } }