Page 1 of 1

What's the output of the following program? static int check(String str) { if (str.length() <= 1) return str.

Posted: Thu May 05, 2022 1:40 pm
by answerhappygod
What's the output of the following program?
static int check(String str) {
if (str.length() <= 1)
return str.length() ;
if (str.charAt(0) == str.charAt(str.length() - 1))
{
return 1 + check(str.substring(1, str.length()
- 1));
} else {
return 0;
}
}
public static void main(String[] args) {
System.out.println(check("abba");
System.out.println(check("abeba");
System.out.println(check("abbcdebba");
}