BuzzFizz Program in Java

Advertisements

Prev Tutorial Next Tutorial

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

Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements