At Westonci.ca, we provide reliable answers to your questions from a community of experts. Start exploring today! Discover in-depth answers to your questions from a wide network of experts on our user-friendly Q&A platform. Our platform provides a seamless experience for finding reliable answers from a network of experienced professionals.

Code a program that will go through all the numbers from 1 to 100 and print them. However, if the number is evenly divisible by 3 then print the word "fizz" instead of the number. If the number is evenly divisible by 5 then print the word "buzz" instead of the number. And, if the number is evenly divisible by both 3 and 5, print the word "fizz buzz" instead of the number. Use a loop, and use modulus division. Only the driver class is needed, and in main just call 1 method called fizzBuzz().
In java.

Sagot :

Answer:

public class Main

{

   // required method

   public static void fizzBuzz(){

       // looping through 1 to 100

       for(int i = 1; i <= 100; i++){

           //if number is evenly divisible by both 3 and 5

           if(i%3 == 0 && i%5 == 0){

               System.out.println("fiz buzz");

           }

                   // if number is divisible by 3

           else if (i%3 == 0){

               System.out.println("fizz");

           }

                        // if number is divisible by 5

           else if (i%5 == 0){

               System.out.println("buzz");

           }

                       // if number is not divisible by both 3 and 5

           else {

               System.out.println(i);

           }

       }

   }

       // main method

       public static void main(String[] args) {

           //calling function

               fizzBuzz();

       }

}

Explanation:

View image tallinn