Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WordBoolean {
- private static final String[] FIRST_ROW = {"q", "w", "e", "r", "t", "y", "u", "i", "o", "p"};
- private static final String[] SECOND_ROW = {"a", "s", "d", "f", "g", "h", "j", "k", "l"};
- private static final String[] THIRD_ROW = {"z", "x", "c", "v", "b", "n", "m"};
- public boolean wordCheck(String word) {
- int char_count = word.length();
- int counter1 = 0;
- int counter2 = 0;
- int counter3 = 0;
- String[] arrWord = word.split("");
- for (int i = 0; i < char_count; i++) {
- for (String element : FIRST_ROW) {
- if (arrWord[i].equals(element)) {
- counter1 = counter1 + 1;
- }
- }
- }
- for (int i = 0; i < char_count; i++) {
- for (String element : SECOND_ROW) {
- if (arrWord[i].equals(element)) {
- counter2 = counter2 + 1;
- }
- }
- }
- for (int i = 0; i < char_count; i++) {
- for (String element : THIRD_ROW) {
- if (arrWord[i].equals(element)) {
- counter3 = counter3 + 1;
- }
- }
- }
- if (counter1 == char_count ||
- counter2 == char_count ||
- counter3 == char_count) {
- return true;
- }
- return false;
- }
- public static void main(String[] args) {
- WordBoolean newWord = new WordBoolean();
- System.out.print(newWord.wordCheck("qwer"));
- }
- }
Add Comment
Please, Sign In to add comment