+ 6

How can i get the following output using java, i tried i*=3i to print buzz but compiler os showing error. Can anybody help me.

1 2 buzz 4 fizz buzz 7 8 buzz fizz 11 buzz 13 14 buzz fizz

11th Jun 2017, 1:57 PM
Nitin Kumar
Nitin Kumar - avatar
3 Respostas
+ 14
public class Program { public static void main(String[] args) { for (int stp = 1; stp < 50; stp++) { if (stp%3==0&&stp>0) { System.out.println("buzz"); } else if (stp%5==0&&stp>0) { System.out.println("fizz"); } else if (stp%15==0&&stp>0) { System.out.println("buzz fizz"); } else { System.out.println(stp); } } } }
11th Jun 2017, 2:12 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 5
Its not getting the last word buzz fizz altogether on 15. and thanks it helps.
11th Jun 2017, 2:17 PM
Nitin Kumar
Nitin Kumar - avatar
+ 5
#Thanks valentinHacker i Got it. :) class Pattern{ public static void main(String[] args){ int i=1; for(i=1;i<=15;i++) if(i%3==0 && i%5 ==0) System.out.println("Buzz Fizz"); else if (i%3==0) System.out.println("Buzz"); else if (i%5==0) System.out.println("Fizz"); else System.out.println(i); } }
11th Jun 2017, 7:13 PM
Nitin Kumar
Nitin Kumar - avatar