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
1
Expert's answer
2016-09-01T14:15:04-0400
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"; }
Comments
Leave a comment