Skip to content

Instantly share code, notes, and snippets.

@bastienapp
Created September 26, 2019 14:55
Show Gist options
  • Save bastienapp/a96c5763a56ceac0f8c3d183b240ca36 to your computer and use it in GitHub Desktop.
Save bastienapp/a96c5763a56ceac0f8c3d183b240ca36 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class FizzBuzz {
public static void main (String [] args) {
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
String result = fizzBuzz(i);
System.out.println("Le résultat est : " + result);
}
public static String fizzBuzz(int n) {
if (n % 3 == 0 && n % 5 == 0) {
return "FizzBuzz";
}
if (n % 5 == 0) {
return "Buzz";
}
if (n % 3 == 0) {
return "Fizz";
}
return Integer.toString(n);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment