Hi! I'm a total beginner and I was wondering if someone can help me with this code.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hi! I'm a total beginner and I was wondering if someone can help me with this code.
Last edited by momdubsnam; August 5th, 2020 at 09:37 AM.
The test for the largest and smallest numbers should be inside of the do{}while loop, NOT after the loop.
If you don't understand my answer, don't ignore it, ask a question.
Thank you for the answer! However, when I try to do that, I get an error on the very last bracket saying "Syntax error, insert "while ( Expression ) ;" to complete DoStatement". I can't figure out what I'm doing wrong.
Please post the code that gives the error
and copy and paste here the full text of the error message.
Check that the {}s are properly paired.
If you don't understand my answer, don't ignore it, ask a question.
Yes that is probably the problem.messed up the brackets in my code
Not all the }s are inline and below the start of the line with the pairing {
For example:
} else if (userNumber > largestNumber) { //<<<<< Here is its pair largestNumber = userNumber; } //<<<<<<< This should be beneath the start the line with the pairing {
Move the noted } to the right so it pairs with the {
What is this hanging { doing?
Remove that {{ //<<<<<< What is this for? if (userNumber < smallestNumber) {
If you don't understand my answer, don't ignore it, ask a question.
Sorry, what do you mean with "to the right"? I've been trying but can't seem to get it right...
By to the right I mean add spaces before the character so that it moves to the rightwhat do you mean with "to the right"?
For example:y x << this x is to right of the above y
--- Update ---
I said:where exactly do you mean with "beneath the start line"?below the start of the line with the pairing {if(test) { ^ this is the start of the code on the line with the { } // this should be beneath the start of the line with the pairing {
If you don't understand my answer, don't ignore it, ask a question.
Thanks. This removes the error but it doesn't solve the problem unfortunately. It still prints the last input instead of the smallest and largest. Happy for any suggestions!
Can you post the new code?
Also add some comments about what the program is going to do with the input from the user. What steps will it take to find the smallest and the largest values?
The comments should describe what the code is going to do.
I use the comments to check that the code is doing what it is supposed to do.
If you don't understand my answer, don't ignore it, ask a question.
What should the program do with the number it reads from the user?
What if you did this manually?
Some one gives you values one at a time and you are required to keep the smallest one in one pile and the largest in another.
Start in the middle (assume that you have gotten past the first few numbers). You get a value from the user. What do you do with that value?
What do you look at and what decisions do you make?
Later we'll go back and work on the first values.
If you don't understand my answer, don't ignore it, ask a question.