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();
}
}
}
Java Interview Question,Java tutorial and Java related Stuffs
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”.
Subscribe to:
Post Comments (Atom)
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 { /**...
-
Below are the some question which are generally asked in Java interview question from Abstract class and interface. Question-Can abstract ...
-
First way to do it as below, String s1 = "First"; String s2 = "Second"; s1=s1+" "+s2; s2=s1.split("...
No comments:
Post a Comment