Mike Rothgeb

Ranch Hand

Posts: 38

posted 1 year ago

I am working on an assignment that asks the following question:

Since the smallest, middle, and largest numbers are unknown, assign input1 to the smallest, middle, and largest variables.

I am somewhat confused here because we are not asked to have a return statement that assigns a value to input1 as being the smallest, middle, or largest integer input.

By having return statements showing input2 as one of the three, as well as input3, is that in effect satisfying the request?

If the answer is no, will I have to write the return statements differently, and actually assign input1 to the three? If so, I have hit a road block I think.

If you prefer to see all the instructions please let me know and I will post them.

Here is the code below:

Since the smallest, middle, and largest numbers are unknown, assign input1 to the smallest, middle, and largest variables.

I am somewhat confused here because we are not asked to have a return statement that assigns a value to input1 as being the smallest, middle, or largest integer input.

By having return statements showing input2 as one of the three, as well as input3, is that in effect satisfying the request?

If the answer is no, will I have to write the return statements differently, and actually assign input1 to the three? If so, I have hit a road block I think.

If you prefer to see all the instructions please let me know and I will post them.

Here is the code below:

posted 1 year ago

That sentence doesn't make a whole lot of sense to me, but maybe in context it would. Why not post the full instructions.

Since the smallest, middle, and largest numbers are unknown, assign input1 to the smallest, middle, and largest variables.

That sentence doesn't make a whole lot of sense to me, but maybe in context it would. Why not post the full instructions.

All things are lawful, but not all things are profitable.

Mike Rothgeb

Ranch Hand

Posts: 38

posted 1 year ago

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

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

posted 1 year ago

Okay, it looks like the original quoted line just means this:

The confusion is was that I didn't that "smallest", "middle", and "largest" were variable names. Also, this line:

means, "Assign the value of the variable input2 to the variable called largest."

The confusion is was that I didn't that "smallest", "middle", and "largest" were variable names. Also, this line:

Assign input2 to the largest variable

means, "Assign the value of the variable input2 to the variable called largest."

All things are lawful, but not all things are profitable.

Mike Rothgeb

Ranch Hand

Posts: 38

posted 1 year ago

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?

posted 1 year ago

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.

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.