Advertisement
zachdyer

FizzBuzz in Java

May 24th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1.         /*
  2.         FizzBuzz
  3.        
  4.         Prints 1 to 100 and for every multiple of 3 it prints Fizz and every multiple of 5 it prints Buzz.
  5.         If the number is a multiple of 3 and 5 it will print "FizzBuzz".
  6.         */
  7.        
  8.         for(int i = 1; i <= 100; i++){
  9.             if(i % 3 == 0 && i % 5 == 0){
  10.                 System.out.println("FizzBuzz");
  11.             } else if(i % 3 == 0){
  12.                 System.out.println("Fizz");
  13.             } else if(i % 5 == 0){
  14.                 System.out.println("Buzz");
  15.             } else {
  16.                 System.out.println(i);
  17.             }
  18.            
  19.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement