-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathFizzBuzz.java
More file actions
21 lines (19 loc) · 849 Bytes
/
FizzBuzz.java
File metadata and controls
21 lines (19 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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);
}
}
}