首先创建一个新的Android工程,下面是页面布局:
Java代码:
我们先来分析一下如何完成的步骤:
1.首先,先完成生成随机数。(包括随机生成几组数字,范围为多少的数字,四则运算符号等);
2.要完成具体逻辑,先指定随机生成几组数字,然后再排列数字和四则运算符号
下面代码随机生成数字的每种情况只写了一种:
private void question() {
java.util.Random random=new java.util.Random();
//先指定随机生成几组数字(2~4);
int temp= random.nextInt(3)+2;
//随机生成(0~3)四个数字分别对应:+,-,×,÷
//如果随机到四组数字,则会有三个运算符
int signal=random.nextInt(4);//第一个运算符
int signal1=ran