1 回答

TA貢獻(xiàn)18條經(jīng)驗(yàn) 獲得超10個(gè)贊
//利用隨機(jī)數(shù)來(lái)搞事
//雖然寫的不好,但意思是差不多的
public class Test{
public static void main(String[] args){
int m = (int)(Math.random()*100); //隨機(jī)數(shù)1,范圍(0到99);
int n = (int)(Math.random()*100); //隨機(jī)數(shù)2,范圍(0到99);
int c = (int)(Math.random()*4); //隨機(jī)數(shù)3, 范圍(0到3),用于隨機(jī)產(chǎn)生加減乘除
int num = 0;
switch(c){
case 0:
num = m + n;
System.out.println(m+" + "+n+" = ?");
break;
case 1:
num = m - n;
System.out.println(m+" - "+n+" = ?");
break;
case 2:
num = m * n;
System.out.println(m+" * "+n+" = ?");
break;
case 3:
num = m / n;
System.out.println(m+" / "+n+" = ?");
break;
}
System.out.println("正確答案是:" + num);
}
}
添加回答
舉報(bào)