• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Assigning variables

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Mike Rothgeb
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

Assign input2 to the largest variable


means, "Assign the value of the variable input2 to the variable called largest."
 
Mike Rothgeb
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

 
Ranch Hand
Posts: 116
2
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mike Rothgeb
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I really appreciate your assistance. I knew the answer was staring me in the face, I just couldn't see it. The perils of being green......

Thanks again!

Mike
 
I would challenge you to a battle of wits, but I see you are unarmed - shakespear. Unarmed tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic