Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3. public class Lab5 {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. String prompt = β€œEnter a grade 0-100\n(Hit Cancel to abort)”;
  8. int x=0;
  9. String str;
  10. for (;;)
  11. {
  12. str = JOptionPane.showInputDialog(prompt);
  13. if (str==null || str.equals(""))
  14. break;
  15. x = Integer.parseInt(str);
  16. if (x>=0 && x<=100) // input is valid.
  17. break;
  18. JOptionPane.showMessageDialog( null, "Invalid grade, try again");
  19. }
  20. if (str != null && !str.equals(""))
  21. JOptionPane.showMessageDialog( null, "The grade is " + x);
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement