Fizz Buzz

Write a program , Output from 1 reach n String representation of numbers .

*
If n yes 3 Multiple of , output “Fizz”;

*
If n yes 5 Multiple of , output “Buzz”;

*
If n At the same time 3 and 5 Multiple of , output “FizzBuzz”.

Examples :
n = 15, return : [ "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz",
"11", "Fizz", "13", "14", "FizzBuzz" ]
code
class Solution { public List<String> fizzBuzz(int n) { List<String> list = new
ArrayList<>();for(int i=1;i<=n;i++){ if(i % 15 == 0){ list.add("FizzBuzz"); }
else if(i%3==0){ list.add("Fizz"); }else if(i%5==0){ list.add("Buzz"); }else{
list.add(String.valueOf(i)); } }return list; } }

Technology
©2019-2020 Toolsou All rights reserved,
element ui Drop down box search function python Short circuit logic in JAVA Convert a string to a numeric type ( Essence )2020 year 6 month 26 day C# Class library Enum( Extension method )( Essence )2020 year 7 month 15 day Wechat applet template Use of Element-UI Implementation of secondary packaging TreeSelect Tree drop-down selection component rk3399_android7.1 debugging USB Summary of Bluetooth module ( Essence )2020 year 7 month 13 day Wechat applet Inter communication page Vue el-select obtain label value element-ui Of el-date-picker Component get value