-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFIZZ_STRING.java
More file actions
30 lines (23 loc) · 791 Bytes
/
FIZZ_STRING.java
File metadata and controls
30 lines (23 loc) · 791 Bytes
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
27
28
29
30
/*
Given a string str, if the string starts with "f" return "Fizz".
If the string ends with "b" return "Buzz". If both the "f" and "b" conditions are true,
return "FizzBuzz". In all other cases, return the string unchanged. (See also: FizzBuzz Code)
fizzString("fig") → "Fizz"
fizzString("dib") → "Buzz"
fizzString("fib") → "FizzBuzz"
*/
package school;
public class FIZZ_STRING {
public static void main(String[] args){
String answer = fizzString("fig");
System.out.println(answer);
}
public static String fizzString(String str) {
char start = str.charAt(0);
char end = str.charAt(str.length()-1);
if(start =='f' && end=='b'){return ("FizzBuzz");}
else if(start=='f'){return ("Fizz");}
else if(end=='b'){return ("Buzz");}
return str;
}
}