java - How to check entered String in a loop with condition? -
I want to write a program that gives the user a string of four boundaries (for example 10 characters 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 some piece of code for it but it does not work yet, because I do not know how to prompt the user again or other easy way to start How to start the process?
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 named the input variable as 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