/**
* Write a description of class GenQuestion here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
public class GenQuestion
{
Random objRandom;
public GenQuestion()
{
long seed = Calendar.getInstance().getTimeInMillis();
objRandom = new Random(seed);
}
private void geneAndPrint()
{
StringBuffer buff = new StringBuffer();
buff.append("加法题的作案是: ");
for(int i=1;i<=5;i++)
{
int a = objRandom.nextInt(90) + 10;
int b = objRandom.nextInt(90) + 10;
System.out.println(a + "+" + b + "=?");
buff.append(a+b);
buff.append(" ");
}
System.out.println(buff.toString());
}
public static void main(String args[])
{
GenQuestion obj = new GenQuestion();
obj.geneAndPrint();
}
}
本文介绍了一个使用Java编写的简单程序,该程序能够随机生成五道加法题目,并打印出题目及答案。通过设置随机种子为当前时间毫秒数,确保每次运行程序时生成的题目不同。
1311

被折叠的 条评论
为什么被折叠?



