标签:
import java.util.Scanner; import java.util.*; public class sizeyunsuan { public static void main(String[] args) { Scanner in=new Scanner(System.in); int i=0,j=0,k=0,l=0,n=0,sum=0,result=0; int []num=new int[5]; String []a={"+","-","*","/"}; for(i=0;i<30;i++){ for(k=0;k<5;k++){ num[k]=(int)(Math.random()*100); } System.out.print(num[n]); for(l=0;l<3;l++){ j=(int)(Math.random()*4); if(j==0){ result=num[i]+result; System.out.print(‘+‘); } if(j==1){ result=num[i]-result; System.out.print(‘-‘); } if(j==2){ result=num[i]*result; System.out.print(‘*‘); } if(j==3){ result=result/num[i]; System.out.print(‘/‘); } n++; System.out.print(num[n]); } System.out.println(‘ ‘); System.out.println("请输入答案:"); int sum1=in.nextInt(); if(sum1==result){ System.out.println("答案正确!"); } else{System.out.println("答案错误,正确答案等于"+sum);} } } }
1)不知道如何规范的计算出结果,因为我的是从左往右运算,而实际上应该先乘除后加减!
2)不懂如何合适的添加括号
标签:
原文地址:http://www.cnblogs.com/201306114345Steven/p/4415518.html