You're a P.E. teacher, and you decide to play a game at a distance of five minutes after class. At this time there are 100 students in class. The rules of the game are:
1. You first say three different special numbers, the requirement must be single-digit, such as 3, 5, 7.
2. Let all the students into a team, and then numbered off in order.
3. When the number of students is numbered, if the reported figures are multiples of the first special number (3), then it is not possible to say the number, but to say fizz; if the reported figures
is a multiple of the second special number (5), say buzz; If the reported number is a multiple of the third special number (7), say whizz.
4. When the number of students is numbered, if the reported figures are simultaneously multiples of two special numbers, special treatment should also be taken, such as the first special number and the second special
The number of multiples, then can not say that number, but to say Fizzbuzz, and so on. If it's a multiple of three special numbers, say fizzbuzzwhizz.
5. When a student is numbered, if the reported number contains the first special number, then it is not possible to say the number, but to say the corresponding word, such as the first special number in this case
is 3, then to report 13 of the students should say fizz. If the number contains the first special number, then ignore Rule 3 and rule 4, for example, to report 35 of the students only reported fizz, do not report buzzwhizz.
Copy Code code as follows:
Package Com.hq.baoshu;
Import Java.util.Scanner;
public class Baoshu {
/*
@author Huangqun
JDK version 1.6
Window 7 32bit
*/
public static void Main (String args[]) {
Test entrance
int sum=100;
Scanner sc=new Scanner (system.in);
int num1=0,num2=0,num3=0;
while (num1<=0| | num1>=10| | num2<=0| | num2>=10| | num3<=0| | num3>=10) {
System.out.println ("Please enter three integers less than 10:");
Num1=sc.nextint ();
Num2=sc.nextint ();
Num3=sc.nextint ();
}
for (int i=1;i<=sum;i++) {
System.out.println (Baoshu (num1,num2,num3,i));//Call implementation method
}
}
/*
* Implementation method
*/
public static String Baoshu (int num1,int num2,int num3,int i) {
StringBuffer talk=new StringBuffer ("");
talk= (i+ ""). IndexOf (num1+ "") >=0?talk.append ("Fizz")
:(I%num1*i%num2*i%num3!=0?talk.append (i)
:(I%num1==0?talk.append ("fizz"): Talk)
. Append (i%num2==0?) Buzz ":"))
. Append (i%num3==0?) Whizz ":"));
return talk.tostring ();
}
}