BuzzFizz Program in Java
Advertisements
Buzz Fizz Program in Java
Write a program in C which prints the numbers from 1 to 100. But, multiples of 3 should be replaced with "Fizz", multiples of 5 should be replaced with "Buzz" and multiples of both 3 and 5 should be replaced with "FizzBuzz"?.
Buzz Fizz Program in Java
class BuzzFizz { public static void main(String arg[]) { int no, i; Scanner s=new Scanner(System.in); System.out.println("Enter range of numbers"); no=s.next(); for(i=1; i<=no; i++) { if((i % (3*5)) == 0) { System.out.println("FizzBuzz\n"); } else if ((i % 5) == 0) { System.out.println("Buzz\n"); } else if ((i % 3) == 0) { System.out.println("Fizz\n"); } else { System.out.println(i); } } } }
Output
Enter Range of number: 20 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz 16 17 Fizz 19 Buzz
Google Advertisment