Skip to content

Commit 19cb2b5

Browse files
authored
add FizzBuzz
1 parent 88c04a1 commit 19cb2b5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Others/FizzBuzz.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//NewCoder171
2+
//FizzBuzz is a popular interview question where you output either Fizz or Buzz when an input value is divisible by 3 or 5 respectively and FizzBuzz if divisible by both 3 and 5
3+
4+
public class buzz {
5+
6+
public static void fizzBuzz(int n){
7+
for (int i = 1; i < n; i++) {
8+
if( i % 3 == 0 && i % 5 == 0){
9+
System.out.println("FizzBuzz");
10+
} else if( i % 3 == 0){
11+
System.out.println("Fizz");
12+
} else if( i % 5 == 0){
13+
System.out.println("Buzz!");
14+
} else {
15+
System.out.println(i);
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy