随机产生10个加法题目,回答完之后计算正确的数目,显示测试花费的时间并列出所有题目,之后决定是否继续下一题目
来源:互联网 发布:linux性能分析工具 编辑:程序博客网 时间:2024/05/12 21:16
import javax.swing.JOptionPane;
public class democratic {
public static void main(String[] args)
{
int count,i=1,j=0,k=1,n=0;
long starTime=System.currentTimeMillis();
String output1="",output2="";
while(i<=10)
{
int number1=(int)(Math.random() * 100);
int number2=(int)(Math.random() * 100);
String jieguo1=JOptionPane.showInputDialog("请计算"+number1+"+"+number2+"的和:");
int and=Integer.parseInt(jieguo1);
count=number1+number2;
if(and==count)
{
JOptionPane.showMessageDialog(null, "Your answer is correct");
j++;
}
else
JOptionPane.showMessageDialog(null, "Your answer is wrong");
i++;
output1+="\n"+number1+"+"+number2+"="+jieguo1+((number1+number2==and)?"right":"wrong");
}
long endTime=System.currentTimeMillis();
long wasteTime=endTime-starTime;
double seconds=wasteTime/1000;
JOptionPane.showMessageDialog(null, "你答对了"+j+"道题目\n花费"+seconds+"秒\n题目如下:"+output1);
int option=JOptionPane.showConfirmDialog(null,"continue");
while(option==JOptionPane.YES_OPTION)
{
JOptionPane.showMessageDialog(null, "进入下一题:");
while(k<=10)
{
int number1=(int)(Math.random() * 100);
int number2=(int)(Math.random() * 100);
String jieguo2=JOptionPane.showInputDialog("请计算"+number1+"-"+number2+"的和:");
int cha=Integer.parseInt(jieguo2);
count=number1-number2;
if(cha==count)
{
JOptionPane.showMessageDialog(null, "Your answer is correct");
n++;
}
else
JOptionPane.showMessageDialog(null, "Your answer is wrong");
k++;
output2+="\n"+number1+"-"+number2+"="+jieguo2+((number1-number2==cha)?"right":"wrong");
}
JOptionPane.showMessageDialog(null, "你答对了"+n+"道题目\n题目如下:"+output2);
break;
}
while(option==JOptionPane.NO_OPTION)
{
JOptionPane.showMessageDialog(null, "恭喜!答题结束!");
break;
}
while(option==JOptionPane.CANCEL_OPTION)
{
JOptionPane.showMessageDialog(null, "异常!!!!");
break;
}
}
}
public class democratic {
public static void main(String[] args)
{
int count,i=1,j=0,k=1,n=0;
long starTime=System.currentTimeMillis();
String output1="",output2="";
while(i<=10)
{
int number1=(int)(Math.random() * 100);
int number2=(int)(Math.random() * 100);
String jieguo1=JOptionPane.showInputDialog("请计算"+number1+"+"+number2+"的和:");
int and=Integer.parseInt(jieguo1);
count=number1+number2;
if(and==count)
{
JOptionPane.showMessageDialog(null, "Your answer is correct");
j++;
}
else
JOptionPane.showMessageDialog(null, "Your answer is wrong");
i++;
output1+="\n"+number1+"+"+number2+"="+jieguo1+((number1+number2==and)?"right":"wrong");
}
long endTime=System.currentTimeMillis();
long wasteTime=endTime-starTime;
double seconds=wasteTime/1000;
JOptionPane.showMessageDialog(null, "你答对了"+j+"道题目\n花费"+seconds+"秒\n题目如下:"+output1);
int option=JOptionPane.showConfirmDialog(null,"continue");
while(option==JOptionPane.YES_OPTION)
{
JOptionPane.showMessageDialog(null, "进入下一题:");
while(k<=10)
{
int number1=(int)(Math.random() * 100);
int number2=(int)(Math.random() * 100);
String jieguo2=JOptionPane.showInputDialog("请计算"+number1+"-"+number2+"的和:");
int cha=Integer.parseInt(jieguo2);
count=number1-number2;
if(cha==count)
{
JOptionPane.showMessageDialog(null, "Your answer is correct");
n++;
}
else
JOptionPane.showMessageDialog(null, "Your answer is wrong");
k++;
output2+="\n"+number1+"-"+number2+"="+jieguo2+((number1-number2==cha)?"right":"wrong");
}
JOptionPane.showMessageDialog(null, "你答对了"+n+"道题目\n题目如下:"+output2);
break;
}
while(option==JOptionPane.NO_OPTION)
{
JOptionPane.showMessageDialog(null, "恭喜!答题结束!");
break;
}
while(option==JOptionPane.CANCEL_OPTION)
{
JOptionPane.showMessageDialog(null, "异常!!!!");
break;
}
}
}
1 0
- 随机产生10个加法题目,回答完之后计算正确的数目,显示测试花费的时间并列出所有题目,之后决定是否继续下一题目
- 笔试经典题目--随机产生不重复的N个数字
- 【学习笔记】关于一道fork()之后printf()输出的题目
- 对软件测试工程师面试题目的回答( 转)
- 对软件测试工程师面试题目的回答[转]
- 对软件测试工程师面试题目的回答
- 题目10:计算两百万以下所有质数的和。
- baidu笔试的2个题目题目一解析
- 计算几何的题目
- JAVA--第十周作业编写之一个Teacher类负责给出算术题目,随机给出两个整数并进行运算,并判断回答者的答案是否正确;编写一个GUI类ComputerFrame,回答者可以通过GUI看到题目并给出
- 程序3.题目:打印出所有的"水仙花数
- 值得一看的测试题目
- 测试题目的答案
- 我出的面试题目
- 自己出的JavaScript题目
- printk打印时间在sleep之后不继续,反映不出休眠时间的问题
- 前一阵出的游戏程序测试题目
- 题目1086:最小花费
- 第一行代码笔记,第十五章----如何发布应用
- 企业高并发的成熟解决方案(一) ----负载均衡服务器
- Prime Path
- 【POJ1426】Find The Multiple(搜索+打表)
- JSX学习
- 随机产生10个加法题目,回答完之后计算正确的数目,显示测试花费的时间并列出所有题目,之后决定是否继续下一题目
- PHP抓取页面的几种方式
- 音乐
- 161021
- js正则表达式验证大全
- Ajax的简单使用(1)
- 也谈layout_gravity和gravity的用法
- war文件的简单理解
- JavaScript语法之类型转换