Platinum Partner

FizzBuzz Problem

The Code for FizzBuzz problem in java. For a given n, it prints all the number from 1 to n, But for the number divisible by 3 it prints "fizz", for number divisible by 5 it prints "buzz", and for number divisible by both 3 and 5 it prints "fizzbuzz"


Integer n = 100;
String[] format = new String[]{"%d\n","fizz\n","buzz\n","fizzbuzz"};
for(int i=1;i< n; i++){
    System.out.printf(format[((i%3==0)?1:0) + 2 *((i%5==0)?1:0)] + "",i);
}
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}