Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.ariel.fizzbuzz;
/*
* Fizz Buzz is an interview question designed to help filter out the 99.5% of programming job candidates who can't
* program their way out of a wet paper bag. The text of the programming assignment is as follows :
* "Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number
* and for the multiples of five print "Buzz". For numbers which are multiples of both tree and five print "FizzBuzz".
*/
public class Main {
public static void main(String[] args) {
// write your code here
boolean isFizzBuzz = false;
for (int i = 1; i <= 100; i++) {
if (i %3 == 0) {
System.out.print("Fizz");
isFizzBuzz = true;
}
if (i % 5 == 0) {
System.out.print("Buzz");
isFizzBuzz = true;
}
if(!isFizzBuzz) {
System.out.print(i);
}
System.out.println();
isFizzBuzz = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment