Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
FizzBuzz
//'main' method must be in a class 'Rextester'. //openjdk version '11.0.5' import java.util.*; import java.lang.*; class Rextester { //Complete the implementation of this method //For the given input the following must happen: // -> If the input value is divisable by 3 print "fizz" // -> If the input value is divisable by 5 print "buzz" // -> If the input value is divisable by 3 & 5 print "fizzbuzz" // -> If the input value is not divisable by 3 or 5 print "PING" public static String fizzBuzz(int input) { String output = ""; if (input % 3 == 0) output += "fizz"; if (input % 5 == 0) output += "buzz"; if (input % 7 == 0) output += "pop"; if (output.equals("")) output = "PING"; return output; } public static void main(String args[]) { System.out.println(fizzBuzz(3)); System.out.println(fizzBuzz(5)); System.out.println(fizzBuzz(8)); System.out.println(fizzBuzz(15)); System.out.println(fizzBuzz(30)); System.out.println(fizzBuzz(35)); System.out.println(fizzBuzz(105)); } }
run
|
edit
|
history
|
help
0
Guess Number
// Java Coding Challenge - 06: Print out Fibonacci numbers 0 - 93
amit
Kadane's Algorithm
asdasd
Java Q4
Ways to form Max Heap
java.
Counter.java
1.5