FizzString challenge

Hi,

I am working on below challenge
http://codingbat.com/prob/p137136

I tried my code as below

public String fizzString(String str) {
if(str.beginWith("f")&&str.endsWith("b")){
return "FizzBuzz";
}

else if(str.endsWith("b")){
return "Buzz";
}

else if(str.beginWith("f"){
return "Fizz";
}
else
return str;
 
}

I am getting below result

Compile problems:


Error:      else if(str.beginWith("f"){
                               ^
Syntax error on token ")", ) expected after this token


see Example Code to help with compile problems


how to  improve my approach and design of this challenge. How do i make a

graphical venn or some other relevant diagram to design it before writing single

line of code to decide best strategy?
 Please advise
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
As for compilation errors....did you try this out on your IDE first before jumping into the coding bat website? Your IDE will point you in the direction on how to fix the error.

Take a look at your braces!
Take a look at the String API for the definition of the beginWith(..) method :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ozoCommented:
return str.replaceAll("^f.*b$","FizzBuzz").replaceAll("^f.*","Fizz").replaceAll(".*b$","Buzz");

return ((str.startsWith("f")?"Fizz":"")+(str.endsWith("b")?"Buzz":"")).replaceAll("^$",str);

return str.replaceAll("^f.*?(b?)$","Fizz$1").replaceAll("^((Fizz?)|.*)b$","$2Buzz");
0
awking00Commented:
Error:      else if(str.beginWith("f") => Because the method is beginsWith (needs the s after begin)
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

gudii9Author Commented:
public String fizzString(String str) {
if(str.beginsWith("f")&&str.endsWith("b")){
return "FizzBuzz";
}

else if(str.endsWith("b")){
return "Buzz";
}

else if(str.beginsWith("f")){
return "Fizz";
}
else
return str;
  
}

Open in new window


i still getting error tryin on IDE
0
gudii9Author Commented:
public String fizzString(String str) {
if(str.startsWith("f")&&str.endsWith("b")){
return "FizzBuzz";
}

else if(str.endsWith("b")){
return "Buzz";
}

else if(str.startsWith("f")){
return "Fizz";
}
else
return str;
  
}

Open in new window


it is startsWith not beginsWith.


above passed all tests
0
gudii9Author Commented:
package eePackage;

public class BeginsWithEx {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
	System.out.println("value is=====>"+fizzString("fib"));	
	}
	
	public static String fizzString(String str) {
		if(str.startsWith("f")&&str.endsWith("b")){
		return "FizzBuzz";
		}

		else if(str.endsWith("b")){
		return "Buzz";
		}

		else if(str.startsWith("f")){
		return "Fizz";
		}
		else
		return str;
		  
		}

}

Open in new window

got rightoutput
0
gudii9Author Commented:
FizzBuzz
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.