FizzBuzz Problem In Java Example
Chapter:
Interview Programs
Last Updated:
27-06-2016 17:20:48 UTC
Program:
/* ............... START ............... */
public class JavaFizzBuzz {
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
if (((i % 5) == 0) && ((i % 7) == 0))
System.out.print("fizzbuzz");
else if ((i % 5) == 0)
System.out.print("fizz");
else if ((i % 7) == 0)
System.out.print("buzz");
else
System.out.print(i);
System.out.print(" ");
}
System.out.println();
}
}
/* ............... END ............... */
Notes:
-
Java program that prints the numbers from 1 to 100. But for multiples of five print "Fizz" instead of the number and for the multiples of Seven print "Buzz".
Tags
FizzBuzz Problem, Java, Interview Programs