第三次作业
package g; import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner scan=new Scanner(System.in); int score=0; String condition = ""; char[] chs=new char[]{'+','-','*','/'}; do { Scanner scanner = new Scanner(System.in); for(int i=1;i<=10;i++)//随机出10道题 { int k=(int)(Math.random()*4); int result=0,result1=0,result2=0,result3=0; int a=(int)(Math.random()*10+1);//第一个随机数字10以内的整数 int b=(int)(Math.random()*10+1);//第二个随机数字10以内的整数 switch(k) { case 0: result=a+b; case 1: result1=a-b; case 2: result2=a*b; case 3: result3=a/b; } System.out.println("("+i+")."+a+chs[k]+b+"=?"); System.out.println("请输入你的答案"); int answer=scan.nextInt(); if(answer==-1){ break; }else if(answer==result||answer==result1||answer==result2||answer==result3){ System.out.println("答对了"); score+=10; }else{ System.out.println("打错了"); } System.out.print(""); } } while ("continue".equals(condition)); System.out.println("恭喜你答题完毕!!"); System.out.println("你的分数为"+score); } }
运行结果:
![](https://images2015.cnblogs.com/blog/812015/201510/812015-20151019125933333-1437570175.png)
PSP耗时表:
总结:希望再接再厉。