BuzzFizz Program in Java


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 Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements