# Problem- You are stranded in the Amazon rain forests with a robot who.docx

8 de Feb de 2023
1 de 2

### Problem- You are stranded in the Amazon rain forests with a robot who.docx

• 1. Problem: You are stranded in the Amazon rain forests with a robot who calls himself FizzBuzz. The robot is pretty cool because it does all the cleaning for you, but it has an annoying habit. It gives you random numbers and expects you to say â€œFizzâ€• if the number is divisible by 3, or â€œBuzzâ€ if the number is divisible by 5, or â€œFizz Buzzâ€ if the number is divisible by both 3 and 5. You humor the robot for a while, but itâ€™s getting stressful, and things are coming to a point where your relationship with the robot may suffer if you do not automate these interactions with him. In the program below, the robot will give you a number in the variable â€˜numâ€™. You have to print the appropriate value (â€œFizzâ€, â€œBuzzâ€, â€œFizz Buzzâ€, â€œâ€•) to the system console. What we expect: If the value in â€˜numâ€™ is 3 we expect your program to print â€œFizzâ€•, ditto for 6, and 9. If the value in â€˜numâ€™ is 5, we expect your program to print â€œBuzzâ€•, ditto for 10 and 20. However, if the value in â€˜numâ€™ is 15, we expect you to print â€œFizz Buzzâ€•, ditto for 30. Finally, if the value in â€˜numâ€™ is 7, we expect you to print â€œâ€• an empty string, and ditto for 8, 11, 16, etc. Hint: You can use the % operator to get the remainder from a division operation Learning outcome: After doing this exercise, you should have learned how to: Use the % (modulus operator) Compare two values using one of the comparison operators in Java Make a decision in your code using an if...else if... else branch statement ------------------------------------------------ import java.util.Scanner; public class FizzBuzz { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); System.out.println("Enter the number:"); int num = scanner.nextInt(); ///{ //write your code here //start //end ///} }
• 2. } Solution for(int i=1;i<=n;i++) { if(i%5==0) System.out.println("Buzz"); else if(i%3==0) System.out.println("Fizz"); else if((i%3==0)&&(i%5==0)) System.out.println("FizzBuzz"); else System.out.println(i); } } }