Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.  
  2. /**
  3.  * “Write a program that prints the numbers from 1 to 100.
  4.  * But for multiples of three print “Fizz” instead of the
  5.  * number and for the multiples of five print “Buzz”.
  6.  * For numbers which are multiples of both three and five print “FizzBuzz”."
  7.  *
  8.  * It uses the modulo operator (%) to determine if a number is divisible by another
  9.  */
  10. public class FizzBuzz//everything in Java is a class
  11. {
  12.     public static void main(String [] args)//Every program must have main()
  13.     {
  14.         for (int i=1; i<=100; i++)//count from 1 to 100
  15.         {
  16.             if (i%3!=0 && i%5!=0)//NOT both?
  17.                 System.out.println(i);//just print i
  18.             else
  19.             {
  20.                 if (i%3==0) System.out.print("Fizz");//multiple of 3? Display Fizz
  21.                 if (i%5==0) System.out.print("Buzz");//multiple of 5? Display Buzz
  22.                 // if it is both, by NOT having 'else', it automatically become FizzBuzz
  23.                 System.out.println();
  24.             }
  25.         }
  26.     }
  27. }