Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class Lab5 {
- public static void main(String[] args) {
- String prompt = βEnter a grade 0-100\n(Hit Cancel to abort)β;
- int x=0;
- String str;
- for (;;)
- {
- str = JOptionPane.showInputDialog(prompt);
- if (str==null || str.equals(""))
- break;
- x = Integer.parseInt(str);
- if (x>=0 && x<=100) // input is valid.
- break;
- JOptionPane.showMessageDialog( null, "Invalid grade, try again");
- }
- if (str != null && !str.equals(""))
- JOptionPane.showMessageDialog( null, "The grade is " + x);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement