Created
September 26, 2019 14:55
-
-
Save bastienapp/a96c5763a56ceac0f8c3d183b240ca36 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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