public static boolean getHappy(String line) {
boolean flag = true;
for (int i = 0; i < line.length(); i++) {
if (i == 0 && line.charAt(i) == 'g') {
if (line.charAt(i + 1) != 'g')
flag = false;
} else if (i == line.length() - 1 && line.charAt(i) == 'g') {
if (line.charAt(i - 1) != 'g')
flag = false;
} else {
if (line.charAt(i) == 'g') {
if (line.charAt(i - 1) != 'g'&& line.charAt(i + 1) != 'g')
flag = false;
}
}
}
return flag;
} |