Java implementation of the hook online fizzbuzzwhizz problem example _java

Source: Internet
Author: User

Copy Code code as follows:

Package test;

/**
* You're a P.E. teacher, and you decide to play a game when you have five minutes from 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 digits, such as 3, 5, 7.
* 2. Let all the students take the first team and then count off the order.
* 3. When a student is numbered, if the reported number is a multiple of the first special number (3), it is not possible to say the number, but to say fizz; If the number quoted is a multiple of the second special number (5), Buzz is said, and if the number quoted is a multiple of the third special number (7), then whizz.
* 4. When the students count, if the reported number is also two special number of multiples, but also special treatment, such as the first special number and the second special 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 students count, if the reported number contains the first special number, then also can not say that the number, but to say the corresponding words, such as the first special number in this example 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.
*
* Now, we need you to complete a program to simulate this game, it first accept 3 special numbers, and then output 100 students should count off the number or words.
*
* @author Liuxuewen
*
*/
public class Fizzbuzzwhizz {
public static void Main (string[] args) {
int a = 3;/* First Special word * *
int B = 5;/* Second Special word * *
int C = 7;/* third special word * *
int start = number of 1;/* started
int end = 100;/* number of digits/
string[] output = {"Fizz", "Fizz", "Buzz", "Whizz", "Fizzbuzz", "Fizzwhizz", "Buzzwhizz", "Fizzbuzzwhizz"};/* store Tag string array * *
int index = -1;/* Default string index to -1*/
/* Cycle to count off * *
for (int i = start; I <= end; i++) {
/* First judge the condition of the 5th, then judge the third condition, and finally judge the condition of the 4th.
index = (i% = = A | | i/10 = = a)? 0:-1;
Index = ( -1 = = index)? ((i% A = = 0 && i% = 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 Result * *
System.out.println (( -1 = index i:output[index]);
}
}
}

Related Article

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.