# 簡單的 FizzBuzz 藏有 深度(google 面試題)

# 版本一

`for(int i = 1; i<= n; i++){   if(i%15 == 0){               System.out.println("FizzBuzz");      continue;   }      if(i%3 == 0){         System.out.println("Fizz");         continue;     }      if(i%5 == 0){         System.out.println("Buzz");         continue;     }      System.out.println(i); }`

# 版本二

`for(int i = 1; i <= n; i++){     String result = "";     if(i%3 == 0) result += "Fizz";     if(i%5 == 0) result += "Buzz";     if(result.length() > 0)       System.out.println(result);     else       System.out.println(i);}`

# 版本三

`for(int i = 1; i<= n; i++){     if(i%15 == 0){         System.out.println("FizzBuzz");     } else if(i%3 == 0){         System.out.println("Fizz");     } else if(i%5 == 0){         System.out.println("Buzz");     } else {         System.out.println(i);     }}`

3的倍數印Fizz、5的倍數印Buzz，這兩個條件是獨立的

When doing a whiteboard coding interview and you get stuck, is it okay to explain to the interviewer how you’d use Google to find an answer?

Yes, I’m sure that you could google a solution to this problem. I’m not asking you this question because I’m thinking 「Gee, you might need to solve this exact question in real life. If that happened, could you do it?」 I’m asking because I believe that solving this question gives me an idea of how effectively your brain can solve problems. Your ability to Google the answer is irrelevant.

This is what a good interviewer should do because whiteboard coding is about brain power not Google power. If you have a bad interviewer, well, all bets are off.

2018/10/20 更新