Copy the code code as follows:
package test;
/**
* You are a physical education teacher. When there are five minutes left before the end of a certain class, you decide to play a game. There are 100 students in class at this time. The rules of the game are:
*
* 1. You first name three different special numbers, which must be single digits, such as 3, 5, and 7.
* 2. Let all students form a team and then count in order.
* 3. When students report numbers, if the number reported is a multiple of the first special number (3), then the number cannot be said, but Fizz; if the number reported is a multiple of the second special number (5) , then say Buzz; if the reported number is a multiple of the third special number (7), then say Whizz.
* 4. When students report numbers, if the reported number is a multiple of two special numbers at the same time, special treatment is also required. For example, if the first special number and the second special number are multiples, then the number cannot be said, but I mean FizzBuzz, and so on. If it is a multiple of three special numbers at the same time, say FizzBuzzWhizz.
* 5. When students report numbers, if the reported number contains the first special number, they cannot say the number, but must say the corresponding word. For example, in this example, the first special number is 3, then report it The 13-year-old students should say Fizz. If the number contains the first special number, then rules 3 and 4 are ignored. For example, a student who wants to report 35 will only report Fizz, not BuzzWhizz.
*
* Now, we need you to complete a program to simulate this game. It first accepts 3 special numbers, and then outputs the numbers or words that 100 students should report.
*
* @author liuxuewen
*
*/
public class FizzBuzzWhizz {
public static void main(String[] args) {
int a = 3;/*first special word*/
int b = 5;/*The second special word*/
int c = 7;/*The third special word*/
int start = 1;/*The number to start counting*/
int end = 100;/*number to end reporting*/
String[] output = { "Fizz", "Fizz", "Buzz", "Whizz", "FizzBuzz", "FizzWhizz", "BuzzWhizz", "FizzBuzzWhizz" };/*Storage flag string array*/
int index = -1;/*The default string index is -1*/
/*Loop for counting*/
for (int i = start; i <= end; i++) {
/*Judge the 5th condition first, then the 3rd condition, and finally the 4th condition*/
index = (i % 10 == a || i / 10 == a) ? 0 : -1;
index = (-1 == index) ? ((i % a == 0 && i % b == 0) ? 4 : (i % a == 0 && i % c == 0) ? 5 : (i % b == 0 && i % c == 0) ? 6 : -1) : index;
index = (-1 == index) ? ((i % a == 0) ? 1 : (i % b == 0) ? 2 : (i % c == 0) ? 3 : -1) : index;
/*Output results*/
System.out.println((-1 == index ? i : output[index]));
}
}
}