I am trying to create a method that gives a boolean:
Public Boolean is StringValid (string) S {boolean isValid; String floating = null; // Only the combination of 'A', 'B', 'C' is allowed (int i = 0; i & lt; s.length (); i ++) {temp = s.sstring (i, i + 1); If (temp.equals ("A") | temp.equals ("B") | temp.equals ("C")) {isValid = true; } Else {isValid = false; }} Return isValid; }
But I get a compiler error, "Say that the local variable is not started".
What I'm trying to do is take a string and test every letter of it, if any letters are found in String except A, B or C, then return the isStringValid method incorrectly. Should give. After checking every letter, A, B or C can be found that the method may be correct.
I think I'm having trouble finding the scope of the local variable if / else What is the proper method of returning from within the blocks? If this is not possible, what would you suggest the best way to design?
Thank you in the avdance.
I agree with the answers that say you should start the isvalid boolean variable.
However, if you include a character other than 'a' 'b' or 'c' *, then you should include a
/ * * Can do whatever you want with. / Public Boolean is Stringwaly (strings) {Return! Pattern.match ("($ ^ | [^ abc] +)", s); } [ABC] means that you are checking that what is included in the character 'A', 'B' or 'C' [^ abc] means that you are checking that Is there a character in which there is none of 'A', 'B' or 'C'. [^ Abc] + This means that you are checking that if any of the at least one character 'A', 'B' or 'C' is not.
$ ^ means empty strings
Comments
Post a Comment