Answered step by step
Verified Expert Solution
Question
1 Approved Answer
the output of cac1 should be false, but the output was true; what is wrong with my code? can you fix it for me? public
the output of "cac1" should be false, but the output was true;
what is wrong with my code? can you fix it for me?
public static void main(String[] args) { LAD022 a = new LAD022(); Systen: out.println(a.isRight ("caca")); System.out.println(a.isRight ("cacl")); 1/ why the number 1 is works here ? public class LAD022 { public boolean isRight (String w) { if (w.length() == 0) { return true; } else if (w.length() == 1) { if (w.contains ("a") 11 w.contains ("b")) { return true; } else { return false; } else if (w.length() == 2) { if (w.startsWith("a") II w.startsWith("b") && w.endsWith("C") 11 w.endsWith("d")) { return true; } else { return false; } else if (w.length() > 2) { if (w.startsWith("C") II w.startsWith("d") && w.endsWith("a") 11 w.endsWith("b")) { return isRight (w.substring(1, w.length()-1)); } else { return false; return false; Output - Labo2 (run) x run: true true BUILD SUCCESSFUL (total time: 0 seconds)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started