Problem Description

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.

Code for Strings FizzBuzz

import java.util.*;
class Main {
  public static void main(String args[]) {
      String word;
      Scanner sc=new Scanner(System.in);
      word=sc.nextLine();
      int n=word.length();
      if(word.charAt(0)=='f' && word.charAt(n-1)=='b')
      {
          System.out.println("FizzBuzz");
      }
      else if(word.charAt(0)=='f')
      {
          System.out.println("Fizz");
      }
      else if(word.charAt(n-1)=='b')
      {
          System.out.println("Buzz");
      }
     
      else
      {
          System.out.println(word);
      }
  }
}

Output Examples:

Example Input: fuel
Output: Fizz
Example Input: bob
Output: Buzz
Example Input: fib
Output: FizzBuzz
Example Input: goodness
Output: goodness