Advertisement
jessicakennedy1028

Java FizzBuzz

Sep 9th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. // Java program to print Fizz Buzz
  2. import java.util.*;
  3. class FizzBuzz
  4. {
  5.     public static void main(String args[])
  6.     {    
  7.         int n = 100;
  8.  
  9.         // loop for 100 times
  10.         for (int i=1; i<=n; i++)                                     
  11.         {
  12.             // number divisible by 5, print 'Buzz'
  13.             // in place of the number
  14.             if (i%5==0)  
  15.                 System.out.print("Buzz"+"\n");
  16.  
  17.             // number divisible by 3, print 'Fizz'
  18.             // in place of the number
  19.             else if (i%3==0)     
  20.                 System.out.print("Fizz"+"\n");   
  21.  
  22.             // number divisible by 15(divisible by
  23.             // both 3 & 5), print 'FizzBuzz' in
  24.             // place of the number
  25.             else if (i%15==0)                                                    
  26.                 System.out.print("FizzBuzz"+"\n");
  27.                
  28.             else // print the numbers
  29.                 System.out.print(i+"\n");                        
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement