java - int variable comparison returning a boolean value -
i have boolean method doing error checking on string. have int class constant called "numwords" = 8. pass string boolean method word count on string using .split , .length. int called "words" counts number of words in string. after done want if statement comparing words against numwords. if equal in number return true else false. have tried == , .equals nothing works. ideas?
public static final int numwords = 8; boolean test = true; string sentence = "i man"; test = check(sentence); public static boolean check (string sentence) { boolean x = true; string[] s = sentence.split(" "); int words = s.length; if (words == numwords) { x = true; } else { x = false; } return x; }
i have tried == , never evaluates false
i have tried .equals, int cannot dereferenced
i have tried =, doesn't compile incompatible types
what want if words = 8 equals numwords , returns true. if words 7 or 9 doesn't equal numwords , returns false.
i making guess want return boolean instead of assigning boolean.
public static boolean check (string sentence) { string[] s = sentence.split(" "); int words = s.length; return words == numwords }
Comments
Post a Comment