diff --git a/Programs/FizzBuzz.java b/Programs/FizzBuzz.java new file mode 100644 index 0000000..bb09df1 --- /dev/null +++ b/Programs/FizzBuzz.java @@ -0,0 +1,21 @@ +// Program to demonstrate fizzbuzz algorithm using Java joptionpane- +import javax.swing.*; +import java.util.Random; +import java.util.Scanner; + +public class Main { + public static void main(String[] args) { + String inputMessage = JOptionPane.showInputDialog("Enter a number to determine if it's fizz or buzz"); + int number = Integer.parseInt(inputMessage); + + if (number % 3 == 0 && number % 5 == 0) { + JOptionPane.showMessageDialog(null, "The number is FizzBuzz"); + } else if (number % 3 == 0) { + JOptionPane.showMessageDialog(null, "The number is Fizz"); + } else if (number % 5 == 0) { + JOptionPane.showMessageDialog(null, "The number is Buzz"); + } else { + JOptionPane.showMessageDialog(null, "The number is neither Fizz nor Buzz: " + number); + } + } +} \ No newline at end of file diff --git a/README.md b/README.md index cb3d676..2073ea4 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,7 @@ It is very easy to contribute, you may follow these steps - 99.[RotateLinkedList](https://github.com/PrajaktaSathe/Java/blob/main/Programs/RotateLinkedList.java)-Program to demo rotating a linked list 100. [ReverseString](https://github.com/PrajaktaSathe/Java/blob/main/ReverseString.java) -Program to reverse a String using the java method substring. 101.[Overriding](https://github.com/PrajaktaSathe/Java/blob/main/Programs/Overriding.java)-Program to demo overriding in java +102. [FIZZBUZZ](https://github.com/lokytech5/Java-FizzBuzz/blob/master/src/Main.java)-Program to demo fizzBuzz algorithm using java joptionpane. # Contributors - ## A big thank you to all our contributors!!!