Skip to content

Commit

Permalink
Add Java Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
MadhavBahl committed Dec 19, 2018
1 parent e8c8252 commit 30d111c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Day1/Java/Fizzbuzz.java
@@ -0,0 +1,28 @@
/**
* @author: MadhavBahlMD
* @date: 20/12/2018
*/

import java.util.Scanner;

public class Fizzbuzz {
public static void main(String[] args) {

System.out.println("/* ===== Fizz Buzz ===== */");
Scanner input = new Scanner(System.in);
System.out.print("\nEnter a number: ");
int n = input.nextInt();
for (int i=1; i<=n; i++) {
if (i%3 == 0 && i%5 == 0) {
System.out.println("FizzBuzz");
} else if (i%3 == 0) {
System.out.println("Fizz");
} else if (i%5 == 0) {
System.out.println("Buzz");
} else {
System.out.println(i);
}
}

}
}
37 changes: 37 additions & 0 deletions Day1/README.md
Expand Up @@ -7,6 +7,8 @@
**Question**- Write a program that prints the numbers from 1 to n and for multiples of '3' print "Fizz" instead of the number, for the multiples of '5' print "Buzz", and for the numbers which are divisible by both 3 and 5, print FizzBuzz.

![Fizz Buzz](./cover.png)

## JavaScript Implementation

### [Solution 1](./JavaScript/sol1.js)
Expand Down Expand Up @@ -69,4 +71,39 @@ function fizzbuzz (num) {
}

fizzbuzz (17);
```

## Java Implementation

### [Solution 1](./Java/Fizzbuzz.java)

```java
/**
* @author: MadhavBahlMD
* @date: 20/12/2018
*/

import java.util.Scanner;

public class Fizzbuzz {
public static void main(String[] args) {

System.out.println("/* ===== Fizz Buzz ===== */");
Scanner input = new Scanner(System.in);
System.out.print("\nEnter a number: ");
int n = input.nextInt();
for (int i=1; i<=n; i++) {
if (i%3 == 0 && i%5 == 0) {
System.out.println("FizzBuzz");
} else if (i%3 == 0) {
System.out.println("Fizz");
} else if (i%5 == 0) {
System.out.println("Buzz");
} else {
System.out.println(i);
}
}

}
}
```
Binary file added Day1/cover.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 30d111c

Please sign in to comment.