四则运算
2015-03-30 19:54 43陈友沛 阅读(154) 评论(0) 编辑 收藏 举报import java.util.Scanner;
import java.util.*;
public class sizeyunsuan
{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int num1=0,num2=0,i=0,j=0,sum=0;
String []a={"+","-","*","/"};
for(i=0;i<30;i++){
num1=(int)(Math.random()*100);
num2=(int)(Math.random()*100);
j=(int)(Math.random()*4);
if(j==0){
sum=num1+num2;
}
if(j==1){
sum=num1-num2;
}
if(j==2){
sum=num1*num2;
}
if(j==3){
sum=num1/num2;
}
System.out.println("请输入答案:");
System.out.print(num1+a[j]+num2+"=");
int sum1=in.nextInt();
if(sum1==sum){
System.out.println("答案正确!");
}
else{System.out.println("答案错误,正确答案等于"+sum);}
}
}
}