Computer Science, asked by bhan61, 1 year ago





Question: Fizzbuzz Strings

Write a method Met that takes as parameter 1 String. The entire string is in lowercase.

If the string starts with f print Fizz. If the string ends with b return Buzz.
If both the f and b conditions are true, return FizzBuzz. In all other cases, print the string unchanged.

Only write the method - assume that the Class & main method have been defined.

Use the System.out.println() statement for printing.

Example Input: fuel
Output: Fizz
Example Input: lob
Output: Buzz
Example Input: flab
Output: FizzBuzz
Example Input: goodness
Output: Goodness


bhan61: can anyone give me answer

Answers

Answered by nitish8089
4
public static void met(String s){
if(s.charAt(0)=='f'&&s.charAt(s.length()-1)=='b'){
System.out.println("FizzBuzz");
}
else if(s.charAt(0)=='f'){
System.out.println("Fizz");
}
else if(s.charAt(s.length()-1)=='b'){
System.out.println("Buzz");
}
else {
System.out.println(s);
}
}
Attachments:

nitish8089: which class question is this??
bhan61: java
nitish8089: it's language class 9th or 10th??
bhan61: 10
bhan61: can you answer my questions today
Similar questions