Advertisement
piffy

FizzBuzz

May 20th, 2015
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. // This example is from _Java Examples in a Nutshell_. (http://www.oreilly.com)
  2. // Copyright (c) 1997 by David Flanagan
  3. // Slight Editing by Piffy.
  4.  
  5. package fizzbuzz;
  6.  
  7. /**
  8.  *
  9.  * @author piffy2
  10.  */
  11. public class FizzBuzz {
  12.    
  13.     public static  String  FizzBuzz(int x) {
  14.             if (((x % 5) == 0) && ((x % 7) == 0))
  15.                 return "fizzbuzz";  
  16.             else if ((x % 5) == 0)            
  17.                 return "fizz";
  18.             else if ((x % 7) == 0)              
  19.                 return "buzz";
  20.         return ""+x;
  21.     }
  22.  
  23.     /**
  24.      * @param args the command line arguments
  25.      */
  26.     public static void main(String[  ] args) {
  27.         for(int i = 1; i <= 100; i++) {        
  28.             System.out.print(FizzBuzz(i));            
  29.             System.out.print(" ");                
  30.         }
  31.         System.out.println( );
  32.     }
  33.    
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement