Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please show me how to fix my code, I can't figure out why it won't work. SameStarChar.java public class SameStarChar { /** Write the method
Please show me how to fix my code, I can't figure out why it won't work.
SameStarChar.java public class SameStarChar { /** Write the method named sameStarChar(). Given a String str, return true if for every ** (star) in the string, if there are chars both immediately before and after the star, they are the same. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Note: This is a little tricker than it looks. One way to look at the problem is to see in what circumstances you should return false. You only return false if the characters on either side of the * are different. That means that if there are no characters in front of, or behind the *, then you should return true, not false. Examples: sameStarChar("xy*yzz") returns true sameStarChar("xy*zzz") returns false sameStarChar("*xa*az") returns true @param str the input String to process. @return true if the characters before and after are the same. 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45} // TODO Write the sameStarChar method here. public boolean sameStarChar (String str) { int i = 0; boolean answer = true; while (i
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