Answer to Question #324719 in Java | JSP | JSF for Holly

Question #324719

1. FizzBuzz (JAVA)

by CodeChum Admin

Instructions:

  1. Input a positive integer in one line. This will serve as the ending point of your loop.
  2. Loop from 1 to the ending point (inclusive) and perform the following statements:
  3. If the number is only divisible by 3, print "Fizz"
  4. If the number is only divisible by 5, print "Buzz"
  5. If the number is divisible by both 3 and 5, print "FizzBuzz"
  6. If nothing is true in the previous conditions, skip the number

Instructions

  1. Scan a positive integer n and store it in a variable.
  2. Create a counter variable with a value of 1 and create a loop from counter to n.
  3. Print "Fizz" if the counter in the loop is divisible by 3, "Buzz" if the counter is divisible by 5, "FizzBuzz" if it is both divisible by 3 and 5.
  4. Skip the iteration if it is not divisible by 3 or by 5.

Input

A line containing an integer.

15

Output

Multiple lines containing a string.

Fizz
Buzz
Fizz
Fizz
Buzz
Fizz
FizzBuzz




1
Expert's answer
2022-04-07T04:04:14-0400


import java.util.Scanner;


public class App {


	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int number = in.nextInt();
		for (int i = 1; i <= number; i++) {
			if (i % 3 == 0 && i % 5 == 0) {
				System.out.println("FizzBuzz");
			}else
			if (i % 3 == 0) {
				System.out.println("Fizz");
			}else
			if (i % 5 == 0) {
				System.out.println("Buzz");
			}
			
		}


		in.close();
	}


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS