+ 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
3 ответов
+ 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);
}
}
}
}
+ 5
Its not getting the last word buzz fizz altogether on 15. and thanks it helps.
+ 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);
}
}