SHARE
TWEET

Java FizzBuzz

jessicakennedy1028 Sep 9th, 2018 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top