67 238
Assignments Done
99,2%
Successfully Done
In November 2018

Answer to Question #61689 in Java | JSP | JSF for Bill DeShields

Question #61689
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
Expert's answer
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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions