On this one I ask the user to enter a number between 10-24 and if the input is not within the range i asked the user, the while statement will keep asking the user to input a valid number. However, i couldn't figure out how to do this with char values. This is the best i could do but this is still not correct because i need the program to keep asking the user to input a valid letter in a while loop.
I got another program that needs to keep asking the user to input a valid answer but this time with Strings. This is also the best i could do. Now this time this program runs fine but it doesn't give me the correct outcome.
I made the program to ask the user to input "Yes" or "No" and i added a while loop so that if the user dosent input the correct answer, the while loop will keep asking the user to input a correct one. Furthermore, i want the program to ignore cases, so it dosn't matter if they input YES, yes, Yes or no, NO, No and so on. So i tried making the program and as i said it looks fine and runs but when i input the corrext input that i want, it goes to the while loop that was meant for invalid answers when in reality it is correct. Does anyone know how to fix these 2 programs?
And thank you
It seems that the NOT (!) operator had to be outside of the conditional statements instead by the "input.equalsIgnoreCase(y)" part. Now that i put the NOT operator in this position i am now getting the results i need.
Campbell Ritchie wrote:Avoid System.exit; it appears all right in a simple example like yours, but can cause dangerous problems in more complicated programs.
Why are you using option panes for keyboard input? That is very old‑fashioned programming style.
Because i am taking a beginner java programming course and as any beginner textbook, it starts off with the basics.
This, I presume.
jonny Alva wrote:Its "Starting out with JAVA From control structures through objects. Published 2016
jonny Alva wrote:
Please explain, why are you giving user so many choices instead of just: "y for Yes, n for No"?
Would there be difference if user would type 'Y' instead of 'y'?
Try to get good code formatting habits. These are important.
Thinking that it isn't important, and ignoring it, it makes your code look very narrowed, which makes it difficult to read.
3. Have you been taught about methods yet?