Hook net Java pen question sharing _java

Source: Internet
Author: User

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 ();
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.