2023年9月11日 天气:阴
今天学会了如何随机生成四则运算。
public class count {
public static void main(String[] args) {
for(int i=0;i<30;i++){
int firNum=(int)(Math.random()*99)+1;
int secNum=(int)(Math.random()*99)+1;
int operaNum=(int)(Math.random()*4)+1;
if(operaNum==1){
System.out.println(firNum+"+"+secNum+"=");
}
if(operaNum==2){
System.out.println(firNum+"-"+secNum+"=");
}
if(operaNum==3){
System.out.println(firNum+"*"+secNum+"=");
}
if(operaNum==4){
if (secNum!=0&&firNum>secNum){
System.out.println(firNum+"/"+secNum+"=");
}
else if(firNum!=0&&firNum<secNum){
System.out.println(secNum+"/"+firNum+"=");
}
else {
System.out.println("30/15=");
}
}
}
}
}
public static void main(String[] args) {
for(int i=0;i<30;i++){
int firNum=(int)(Math.random()*99)+1;
int secNum=(int)(Math.random()*99)+1;
int operaNum=(int)(Math.random()*4)+1;
if(operaNum==1){
System.out.println(firNum+"+"+secNum+"=");
}
if(operaNum==2){
System.out.println(firNum+"-"+secNum+"=");
}
if(operaNum==3){
System.out.println(firNum+"*"+secNum+"=");
}
if(operaNum==4){
if (secNum!=0&&firNum>secNum){
System.out.println(firNum+"/"+secNum+"=");
}
else if(firNum!=0&&firNum<secNum){
System.out.println(secNum+"/"+firNum+"=");
}
else {
System.out.println("30/15=");
}
}
}
}
}