Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class Loops
- {
- public static void main (String [] args)
- {
- int math, total=0, times=0, n=0;
- int average, pass=0, fail=0, check;
- int mType=JOptionPane.INFORMATION_MESSAGE;
- int result=1;
- do
- {
- String mathString = JOptionPane.showInputDialog("請輸入數學成績\n");
- math= Integer.parseInt(mathString);
- if(math<0 | math>100)
- {
- JOptionPane.showConfirmDialog(null,"請重新輸入數字,介於0~100之間",mathString, JOptionPane.YES_NO_OPTION,mType, null);
- continue;
- }
- else
- {
- n++;
- JOptionPane.showConfirmDialog(null,"第"+n+"位學生數學成績為:"+math+"分\n");
- }
- times++;
- total+=math;
- check=math/10;
- average=total/times;
- switch(check)
- {
- case 10:
- case 9:
- case 8:
- case 7:
- case 6:
- pass++;
- break;
- default:
- fail++;
- break;
- }
- result=JOptionPane.showConfirmDialog(null, "繼續輸入成績嗎?",mathString, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
- if (result==JOptionPane.NO_OPTION)
- {
- JOptionPane.showConfirmDialog(null,"總人數:"+times+"\n總平均值為"+average+"\n總及格人數:"+pass+"\n總不及格人數:"+fail);
- System.exit(0);
- }
- }while(true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement