Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.hawaii.ics314;
- /**
- * An application that will print out all of the numbers from 1 to 100, one per
- * line, except that when the number is a multiple of 3, "Fizz" is printed, when
- * a multiple of 5, "Buzz" is printed, and when a multiple of both 3 and 5,
- * "FizzBuzz" is printed.
- *
- * @author Jayson Gamiao
- * @assignment ICS 314 Assignment 4
- * @date August 31, 2011
- */
- public class FizzBuzz {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // Print out all numbers from 1 to 100.
- for (int number = 1; number < 101; number++) {
- // Print "FizzBuzz" if number is a multiple of 3 and 5.
- if (number % 15 == 0) {
- System.out.println("FizzBuzz");
- // Print "Fizz" if number is a multiple of "Fizz".
- } else if (number % 3 == 0) {
- System.out.println("Buzz");
- // Print "Buzz" if number is a multiple of "Buzz".
- } else if (number % 15 == 0) {
- System.out.println("FizzBuzz");
- // If none of the above is satisfied, print the value of number.
- } else {
- System.out.println(number);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment