Advertisement
wendy890711

0324

Mar 24th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. public class Loops
  3. {
  4. public static void main (String [] args)
  5. {
  6. int math, total=0, times=0, n=0;
  7. int average, pass=0, fail=0, check;
  8. int mType=JOptionPane.INFORMATION_MESSAGE;
  9. int result=1;
  10. do
  11. {
  12. String mathString = JOptionPane.showInputDialog("請輸入數學成績\n");
  13. math= Integer.parseInt(mathString);
  14. if(math<0 | math>100)
  15. {
  16. JOptionPane.showConfirmDialog(null,"請重新輸入數字,介於0~100之間",mathString, JOptionPane.YES_NO_OPTION,mType, null);
  17. continue;
  18. }
  19. else
  20. {
  21. n++;
  22. JOptionPane.showConfirmDialog(null,"第"+n+"位學生數學成績為:"+math+"分\n");
  23. }
  24. times++;
  25. total+=math;
  26. check=math/10;
  27. average=total/times;
  28. switch(check)
  29. {
  30. case 10:
  31. case 9:
  32. case 8:
  33. case 7:
  34. case 6:
  35. pass++;
  36. break;
  37. default:
  38. fail++;
  39. break;
  40. }
  41. result=JOptionPane.showConfirmDialog(null, "繼續輸入成績嗎?",mathString, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
  42. if (result==JOptionPane.NO_OPTION)
  43. {
  44. JOptionPane.showConfirmDialog(null,"總人數:"+times+"\n總平均值為"+average+"\n總及格人數:"+pass+"\n總不及格人數:"+fail);
  45. System.exit(0);
  46. }
  47.  
  48. }while(true);
  49.  
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement