fizzbuzz problem java

Categories: Java 9 Java Java Examples

import java.util.*;

public class Main {

  public static void main(String[] args) {

   StringBuffer sb=new StringBuffer();

   for(int i=1;i<=100;i++){

    if(i%5==0&&i%3==0)

   sb.append("FizzBuzz");

     else

    if(i%5==0)

   sb.append("Buzz");

    else if(i%3==0)

    sb.append("Fizz");

    else

     sb.append(i);


  }

  System.out.println(sb);

}

}

Output

12Fizz4BuzzFizz78FizzBuzz11Fizz1314FizzBuzz1617Fizz19BuzzFizz2223FizzBuzz26Fizz2829FizzBuzz3132Fizz34BuzzFizz3738FizzBuzz41Fizz4344FizzBuzz4647Fizz49BuzzFizz5253FizzBuzz56Fizz5859FizzBuzz6162Fizz64BuzzFizz6768FizzBuzz71Fizz7374FizzBuzz7677Fizz79BuzzFizz8283FizzBuzz86Fizz8889FizzBuzz9192Fizz94BuzzFizz9798FizzBuzz

Top Blogs
Java Retention Policy, SOURCE,CLASS,RUNTIME Published at:- Do you know the top new features of Java 9 Published at:- Why to Learn java Programming? Published at:- How to Optimize Java Apps on Kubernetes Published at:- When and Why Java is utilized for Application Improvement Published at:- Tips and Tricks to Win with Slot Machines 2024 Published at:- Interface and Usability of 1win: User Experience Published at:- Scanner nextLine() ,nextInt() ,nextDouble() method in Java with Examples Published at:- java toUpperCase() and toLowerCase() example Published at:- pushing value at last in java | how to add element at the end of array in java Published at:- fizzbuzz problem java Published at:- Write a program for group words by first character of given string | Java 8 Stream Example Published at:- Write a Java 8 program to calculate the age of a person in years given their birthday Published at:- Write a Java 8 program to calculate the age of a person in years given their birthday Years Months Days Published at:- Write a Java 8 program to print the first 10 odd numbers Published at:- Filter employees by age in Java 8 Lamda steam Published at:- Write a Java 8 program to get the last element of an array string/object Published at:- Filter employees by age set senior if age is greater than 30 in Java 8 Lamda steam Published at:- How to increment salary by 2%, 5%, etc. Using java Published at:- Write a program to find the only duplicate count list in the List Published at:- Write a program to append char in char ex-input- {A, B, C} output->[A_X, B_Y, C_Z] Published at:- Write a program to sum an array without using the sum method Published at:- Write a program to sum an array Published at:- Drop all while condition not meet dropWhile(),dropWhile(Predicate<T> predicate) Published at:- Find the maximum value in a list of integers using Stream & Method Reference Published at:-
R4R.co.in Team
The content on R4R is created by expert teams.