SHARE
TWEET

Untitled

a guest Sep 11th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 412. Fizz Buzz
  2.  
  3. class Solution {
  4.     public List<String> fizzBuzz(int n) {
  5.         List<String> list = new ArrayList<>();
  6.        
  7.         for (int i = 1; i <= n; i++) {
  8.             if (i % 3 == 0 && i % 5 == 0)
  9.                 list.add("FizzBuzz");
  10.             else if (i % 3 == 0)
  11.                 list.add("Fizz");
  12.             else if (i % 5 == 0)
  13.                 list.add("Buzz");
  14.             else
  15.                 list.add(String.valueOf(i));
  16.         }
  17.         return list;
  18.     }
  19.    
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top