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);
}
}
運作結果:
PSP耗時表:
總結:希望再接再厲。