,,,
public class Demo {
public static void main(String[] args) {
int a = (int) (Math.random() * 100);
int b = (int) (Math.random() * 100);
System.out.println(a + "+" + b + "=" + (a + b));
}
}
public static void main(String[] args) {
int a = (int) (Math.random() * 100);
int b = (int) (Math.random() * 100);
System.out.println(a + "+" + b + "=" + (a + b));
}
}
Java生成100以内的随机数,再相加就可以了,很简单的。。
温馨提示:答案为网友推荐,仅供参考
第1个回答 2019-03-14
import java.util.Scanner;
import java.util.Random;
import java.util.Calendar;
public class P
{
public static void main(String[] args)
{
int a,num1,num2,total=10,right=0,wrong=0;
Scanner sc=new Scanner(System.in);
Random r=new Random(Calendar.getInstance().getTimeInMillis());
while(total>0)
{
num1=r.nextInt(101);
num2=r.nextInt(101);
System.out.print(""+num1+"+"+num2+"=");
a=Integer.parseInt(sc.nextLine());
if(a==num1+num2)
{
right++;
System.out.println("答题正确,很好");
}
else
{
wrong++;
System.out.println("答题错误,加油");
}
total--;
}
System.out.println("每题10分,共回答10题,对"+right+"题,错"+wrong+"题。得分:"+(right*10));
}
}
import java.util.Random;
import java.util.Calendar;
public class P
{
public static void main(String[] args)
{
int a,num1,num2,total=10,right=0,wrong=0;
Scanner sc=new Scanner(System.in);
Random r=new Random(Calendar.getInstance().getTimeInMillis());
while(total>0)
{
num1=r.nextInt(101);
num2=r.nextInt(101);
System.out.print(""+num1+"+"+num2+"=");
a=Integer.parseInt(sc.nextLine());
if(a==num1+num2)
{
right++;
System.out.println("答题正确,很好");
}
else
{
wrong++;
System.out.println("答题错误,加油");
}
total--;
}
System.out.println("每题10分,共回答10题,对"+right+"题,错"+wrong+"题。得分:"+(right*10));
}
}