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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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 :)

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");
awking00Information Technology SpecialistCommented:
Error:      else if(str.beginWith("f") => Because the method is beginsWith (needs the s after begin)
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
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
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
gudii9Author Commented:
FizzBuzz
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.