public void startTimer()
{ new java.lang.Thread(new Runnable(){
public void run()
{ while(running)
{ try{
Thread.sleep(1000);//睡一秒
}
catch(Exception e){}
timer++;
time.setText("
已使用:
" + String.valueOf(timer) + " 秒");
} }
}).start();
} private void InitQuestion()
{
questions = new ArrayList(10);
answers = new ArrayList(10);
String[] operations = {"+","-","*","/"};
Random random = new Random();
String operation = null;
int num1 = 0;
int num2 = 0;
for(int i = 0; i < 10; i++)
{
//自动生成运算符
operation = operations[(int)(random.nextDouble()*10*2/5)];
//自动生成2个100以内的数
num1 = (int)(random.nextDouble()*100);
num2 = (int)(random.nextDouble()*100);
if(operation.equals("+"))
{
answers.add(i, s.valueOf(num1+num2));
questions.add(i, num1 + " + " + num2 ); }
else if(operation.equals("-"))
{ answers.add(i, s.valueOf(num1-num2));
answers.add(i, s.valueOf(num1+num2));
//自动生成运算符
operation = operations[(int)(random.nextDouble()*10*2/5)];
//自动生成2个100以内的数
num1 = (int)(random.nextDouble()*100);
num2 = (int)(random.nextDouble()*100);
if(operation.equals("+"))
{ answers.add(i, s.valueOf(num1+num2));
questions.add(i, num1 + " + " + num2 );
} else if(operation.equals("-"))
{ answers.add(i, s.valueOf(num1-num2));
questions.add(i, num1 + " - " +num2);
}