- Where Developers Learn, Share, & Build Careers
I want to write a program that has a given four ranges (for example, 10 characters for a user's string Checks)). If the entry in the string is more than 10 characters, then the user should re-sign again until the user enters a valid string (one word of 10 characters) until the user enters a valid string.
I already have a piece of code for this, but it does not work yet, because I have no idea that the user will be prompted again or in another easy way. How to start the process can be started?
System.out.print ("Input:"); String inputts = input Screenplay (); While (inputChars.length ()> 10) {System.out.print ("Input:"); String inputts = input Screenplay (); // Here is a mistake now} System.out.print ("Output:"); System.out.print ("10 characters in login"); I'm more than just 10 words, then check the entered word, then leave it and prompt the user to enter a word again which is more than 10 Not a character. I am not good in Java yet, so if this question is stupid, then explain to me how to solve it. Thanks in advance
Look at your loop:
while inputChars .length ()> 10) {System.out.print ("Input:"); String inputts = input Screenplay (); } The second line of the loop body resale to the inputcharts variable. You can not do this because it is already in the area. You just want to replace the previous value : inputChars = input.readString (); To avoid duplication, you should also consider restructuring of your code:
string input chords; Do {System.out.print ("Input:"); InputChars = input.readString (); } While (inputChars.length ()> 10); Note that in order to follow the normal Java naming conventions, I have changed the input variable to input . I would actually change both input and inputts more descriptively - in particular, what is the meaning of input data mean at this time
Comments
Post a Comment