Write a program that prompts the user for an even multiple of 29 that is under 50. Respond to the user's input as appropriate
import javax.swing.*;
public class Main {
public static void main(String[] args) {
while (true) {
String str = JOptionPane.showInputDialog(null, "Enter even multiple of 29, that under 50:");
if (str == null) break;
int num;
try {
num = Integer.parseInt(str);
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "This is not a valid number. Try again!");
continue;
}
String respond = "";
if (num < 50 && num % 29 == 0 && num % 2 == 0) respond = "It's OK!";
else {
if (num >= 50) respond += "Number must be less than 50\n";
if (num % 29 != 0) respond += "Number must me multiple of 29\n";
if (num % 2 != 0) respond += "Number must be even\n";
}
JOptionPane.showMessageDialog(null, respond);
}
}
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
JavaJSPJSF