1. 程式人生 > >LintCode 9---Fizz Buzz 問題

LintCode 9---Fizz Buzz 問題

clas list -- span main urn generate sta lintcode

import java.util.ArrayList;
import java.util.List;

public class Lint9 {
/*
 * 判斷能不能被整除
 */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
    }
    public List<String> fizzBuzz(int n) {
        List<String> list = new ArrayList<>();
        
for (int i = 1; i <= n; i++) { if(i%3 == 0 && i%5 == 0) { list.add("fizz buzz"); continue; } else if(i%3 == 0) { list.add("fizz"); continue; } else if(i%5 == 0) { list.add(
"buzz"); continue; }else { list.add(i+""); } } return list; } }

LintCode 9---Fizz Buzz 問題