1、import java.text.DecimalFormat;import java.util.Random;import javax.swing.JOptionPane;public class Practise public static void main(String args)/程序自 动产生算 术题目,100以内任意两个整数间的任意运算(+-*/%)int czs,bczs,op;/操作数,被操作数,运算符号int select=JOptionPane.YES_OPTION;double PcAnswer,SrAnswer;/电脑计算结果,用户输入结果String Input,Ou
2、tput=“,op2,Outp=“n“;/Input接收用户输入结果while(select=JOptionPane.YES_OPTION) czs=(int)(Math.random()*100);/以下三行,随机产生操作数,被操作数,运算符号bczs=(int)(Math.random()*100);op=(int)(Math.random()*5);switch (op) /确定运算符号case 0:PcAnswer=bczs+czs;op2=“ + “;break;case 1:PcAnswer=bczs-czs;op2=“ - “;break;case 2:PcAnswer=bczs
3、*czs;op2=“ * “;break;case 3:PcAnswer=(double)bczs/czs;DecimalFormat df= new DecimalFormat(“0.000“);PcAnswer=Double.parseDouble(df.format(PcAnswer);op2=“ / “;break;default:PcAnswer=bczs%czs;op2=“ % “;break;Input=JOptionPane.showInputDialog(bczs+op2+czs+“=?“).trim();SrAnswer=Double.parseDouble(Input);if(PcAnswer=SrAnswer)/判断正确Outp+=“恭喜你,答对了“;else Outp+=“很遗憾,你答错了“;Output=bczs+op2+czs+“ = “+PcAnswer+“n你的答案是:“+SrAnswer;select =JOptionPane.showConfirmDialog(null, Output+Outp+“nn选择“是”继续做题,选择“ 否”退出程序 “, “公布结果啦“, JOptionPane.YES_NO_OPTION);