This programming problem requires the use of the logical && operators to compare values. Follow the steps below:
Import the Scanner class
Declare Six integer variables (input1, input2, input3, smallest, middle, and largest)
Create a Scanner object and assign integer keyboard input values to the input 1, input2, and input3 variables
Since the smallest, middle, and largest numbers are unknown, assign input 1 to the smallest, middle, and largest variables
Create an if statement with a logical && operator that checks if input2 is greater than input 1 && input2 is greater than input 3. If this condition is true, then input2 must be the largest number. Assign input2 to the largest variable
Create an else if statement with a logical && operator that checks if input2 is less than input 1 && input2 is less than input 3. If this condition is true, then input2 must be the smallest number. Assign input2 to the smallest variable
If none of the conditions you created above are true, then input2 must be the middle number. Create an else statement that assigns input2 to the middle variable
Now write another if, else-if, and else statement set comparing input3 to input and input2
I have done the code over to comply with the instructions. One thing that was not mentioned earlier is that the output has to be in ascending order. When the code is run it displays two lines. One which is in ascending order and the other is mixed order. I cannot see my mistakes here. Can someone offer assistance?
First, the assignment states that you need to assign the values to the "smallest", "middle", and "largest" variables. In your code you are not assigning any values, you are just printing them to the screen. You should do something more like this:
From the first IF statement, all we know is that input2 is larger than both input1 and input3. We don't know however between input1 and input3 which is larger or smaller. We just know what input2 is. The second ELSE IF we know that input2 is smaller than input1 and input3. Again we don't know from this statement whether input1 or input3 are bigger or smaller than eachother. Because of this, we can't print a final ascending order within each statement.
You will need to follow the above logic to finish assigning the variables for input1 and input3. then at the end, you can print the smallest, middle, and largest variable values like so:
Hope this helps. Let me know if you get stuck or need any further clarification.