Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package edu.hawaii.ICS314;
- /**
- * Print class - loops from number 1 to 100. If the number is divisible by 3, "Fizz" is printed. If the number
- * is divisble by 5, "Buzz" is printed. If the number is divisible by both 3 and 5, "FizzBuzz" is printed.
- * Otherwise the number is printed.
- *
- * @author ButuGruv
- *
- */
- public class Print {
- public static void main(String[] args) {
- //loop 1 to 100
- for(int i=1; i<100; i++) {
- //print Fizz if divisible by 3
- if(i%3 == 0) System.out.println("Fizz");
- //print Buzz if divisible by 5
- else if (i%5 == 0) System.out.println("Buzz");
- //print FizzBuzz if divisible by both
- else if (i%5 == 0 && i%3 == 0) System.out.println("FizzBuzz");
- //otherwise print the number
- else System.out.println(i);
- }
- }
- }
Add Comment
Please, Sign In to add comment