examples :
1
2
3 => Fizz
4
5 => Buzz
...
...
15 => FizzBuzz
...
...
so on..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public static void main(String[] args){ for(int x=1;x<=100;x++){ if(x%3==0){ System.out.print("Fizz"); if(x%5==0){ System.out.print("Buzz"); } System.out.println(); } else if(x%5==0) System.out.println("Buzz"); else System.out.println(x); } } |
No comments:
Post a Comment