Posted By

kirkkohler on 09/12/13


Tagged

java fizzbuzz


Versions (?)

FizzBuzz


 / Published in: Java
 

A simple fizzbuzz example written in java.

  1. /**
  2.  *
  3.  */
  4. package com.fizz.buzz;
  5.  
  6. /**
  7.  * @author KKohle001
  8.  * Write a program that prints the numbers from 1 to 100.
  9.  * But for multiples of three print "Fizz" instead of the number and
  10.  * for the multiples of five print "Buzz". For numbers which are
  11.  * multiples of both three and five print "Fizz-Buzz".
  12.  */
  13. public class FizzBuzz {
  14.  
  15. /**
  16. * @param args
  17. */
  18. public static void main(String[] args) {
  19. for(int i = 1; i <= 100; i++){
  20.  
  21. //if multiple of 3 and 5 print Fizz-Buzz
  22. if((i % 3 == 0) && (i % 5 == 0)){
  23. System.out.println("Fizz-Buzz");
  24. // if multiple of 3 print Fizz
  25. } else if(i % 3 == 0){
  26. System.out.println("Fizz");
  27. }
  28. // if multiple of 5 print Fizz
  29. else if(i % 5 == 0){
  30. System.out.println("Buzz");
  31. } else{
  32. System.out.println(i);
  33. }
  34.  
  35. }
  36.  
  37. }
  38.  
  39. }

Report this snippet  

You need to login to post a comment.