Here is my code for hacker rank question. Can somebody suggest improvement?
Question:
We consider a word, to be beautiful if the following two conditions are satisfied:
- No two consecutive characters are the same.
- No two consecutive characters are in the following vowel set: a, e, i, o, u, y. Note that we consider y to be a vowel in this challenge.
Solution:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String w = in.next();
int result = isBeautiful(w);
if (result == 1) {
System.out.print("Yes");
} else
System.out.print("No");
}
static int isBeautiful(String w) {
for (int i = 0; i < w.length() - 1; ++i) {
if (w.charAt(i) == w.charAt(i + 1)) {
return 0;
}
if ( ( isVowel(w.charAt(i)) == isVowel(w.charAt(i + 1)) && (isVowel(w.charAt(i)) == 1))) {
return 0;
}
}
return 1;
}
static int isVowel(char c) {
if ( (c == 'a') || (c == 'e') || (c == 'i') || (c == 'o') || (c == 'u') || (c == 'y') ) {
return 1;
}
return 0;
}
}