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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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");
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply