Following is the program for FizzBuzzProblem. It is program to print numbers from 1 to 100, but if the number is multiple of 3 then number should be replaced with "Buzz", if the number is multiple of 5 then number should be replaced with "Fizz", and if the number is multiple of both 3 and 5 then number should be replaced with "FizzBuzz".
public class FizzBuzzProblem
{
public static void main(String args[])
{
for(int i = 1; i <= 100; i++)
{
if((i % (3*5)) == 0)
{
System.out.println("FizzBuzz");
}
else if ((i % 5) == 0)
{
System.out.println("Buzz");
}
else if ((i % 3) == 0)
{
System.out.println("Fizz");
}
else
{
System.out.println(i);
}
}
}
}
public class FizzBuzzProblem
{
public static void main(String args[])
{
for(int i = 1; i <= 100; i++)
{
if((i % (3*5)) == 0)
{
System.out.println("FizzBuzz");
}
else if ((i % 5) == 0)
{
System.out.println("Buzz");
}
else if ((i % 3) == 0)
{
System.out.println("Fizz");
}
else
{
System.out.println(i);
}
}
}
}
No comments:
Post a Comment