Monday, 12 August 2013

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

public class FizzBuzzProgramme {
    public static void main(String[] args) {
        boolean flag;
        for (int i = 1; i<=100;i++)
        {
            flag = false;
            if (i%3==0)
            {   
                System.out.print("Fizz");
                flag = true;
            }
            if (i%5==0)
            {
                System.out.print("Buzz");
                flag = true;
            }
            if (flag == false)
            {
                System.out.print(i);
            }
            System.out.println();
        }
    }
 
}

No comments:

Post a Comment

Find Duplicate Characters In String using Java

package com.zia.test; import java.util.HashMap; import java.util.Map; import java.util.Set; public class findDuplicateCharacter { /**...