Created
May 5, 2014 06:47
-
-
Save DavyLin/4528e07165717178070a to your computer and use it in GitHub Desktop.
ThoughtWorks的代码题 https://www.jinshuju.net/f/EGQL3D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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