Skip to content

Instantly share code, notes, and snippets.

@DavyLin
Created May 5, 2014 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavyLin/4528e07165717178070a to your computer and use it in GitHub Desktop.
Save DavyLin/4528e07165717178070a to your computer and use it in GitHub Desktop.
ThoughtWorks的代码题 https://www.jinshuju.net/f/EGQL3D
public class FizzTest {
public static void main(String[] args) {
String string = "";
String[] nums = new Scanner(System.in).next().split(",");
for (int i = 1; i <= 100; i++) {
if (String.valueOf(i).indexOf(nums[0]) != -1) {
string += "Fizz";
} else {
if (i % Integer.parseInt(nums[0]) == 0) {
string += "Fizz";
}
if (i % Integer.parseInt(nums[1]) == 0) {
string += "Buzz";
}
if (i % Integer.parseInt(nums[2]) == 0) {
string += "Whizz";
} else if (i % Integer.parseInt(nums[0]) != 0 && i % Integer.parseInt(nums[1]) != 0 && i % Integer.parseInt(nums[2]) != 0) {
string += i;
}
}
string += "\n";
}
System.out.println(string);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment