课堂测试1:
import java.util.Random;
public class Sapp {
public static void main(String[] args) {
Random ran=new Random();
for(int i=1;i<31;i++) {
int a=ran.nextInt(100);
int b=ran.nextInt(100);
int c=ran.nextInt(4);
if(c==0)
{
System.out.print(i+".");
System.out.println(a+"+"+b+"=");
}
else if(c==1&&a>=b)
{
System.out.print(i+".");
System.out.println(a+"-"+b+"=");
}
else if(c==2&&a*b<100)
{
System.out.print(i+".");
System.out.println(a+"*"+b+"=");
}
else if(c==3&&b!=0&&a%b==0)
{
System.out.print(i+".");
System.out.println(a+"/"+b+"=");
}
else
{
i--;
}
}
}
public class Sapp {
public static void main(String[] args) {
Random ran=new Random();
for(int i=1;i<31;i++) {
int a=ran.nextInt(100);
int b=ran.nextInt(100);
int c=ran.nextInt(4);
if(c==0)
{
System.out.print(i+".");
System.out.println(a+"+"+b+"=");
}
else if(c==1&&a>=b)
{
System.out.print(i+".");
System.out.println(a+"-"+b+"=");
}
else if(c==2&&a*b<100)
{
System.out.print(i+".");
System.out.println(a+"*"+b+"=");
}
else if(c==3&&b!=0&&a%b==0)
{
System.out.print(i+".");
System.out.println(a+"/"+b+"=");
}
else
{
i--;
}
}
}
}
课堂测试2:
import java.util.Scanner;
import java.util.Random;
import java.util.Random;
public class Sappp {
static Scanner scan = new Scanner(System.in);
static Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("请输入题目数量:");
int n = scan.nextInt();
System.out.println("请输入每行题目个数:");
int m = scan.nextInt();
int[][] s1=new int[n/3+1][m];
int[][] s2=new int[n/3+1][m];
int[][] s3=new int[n/3+1][m];
Random ran = new Random();
for (int i = 1; i < (n / m)+2; i++) {
for (int l = 1; l < m+1; l++) {
int a = ran.nextInt(100);
int b = ran.nextInt(100);
int c = ran.nextInt(4);
int k=l+(i-1)*m;
if(k>n||(s1[i-1][l-1]==a&&s2[i-1][l-1]==b&&s3[i-1][l-1]==c))
break;
if (c == 0) {
System.out.print(k+ ".");
System.out.print(a + "+" + b + "= ");
s1[i-1][l-1]=a;
s2[i-1][l-1]=b;
s3[i-1][l-1]=c;
} else if (c == 1 && a >= b) {
System.out.print(k + ".");
System.out.print(a + "-" + b + "= ");
s1[i-1][l-1]=a;
s2[i-1][l-1]=b;
s3[i-1][l-1]=c;
} else if (c == 2 && a * b < 100) {
System.out.print(k + ".");
System.out.print(a + "*" + b + "= ");
s1[i-1][l-1]=a;
s2[i-1][l-1]=b;
s3[i-1][l-1]=c;
} else if (c == 3 && b != 0 && a % b == 0) {
System.out.print(k + ".");
System.out.print(a + "/" + b + "= ");
s1[i-1][l-1]=a;
s2[i-1][l-1]=b;
s3[i-1][l-1]=c;
} else {
l--;
}
}
System.out.println("");
}
}
System.out.println("请输入题目数量:");
int n = scan.nextInt();
System.out.println("请输入每行题目个数:");
int m = scan.nextInt();
int[][] s1=new int[n/3+1][m];
int[][] s2=new int[n/3+1][m];
int[][] s3=new int[n/3+1][m];
Random ran = new Random();
for (int i = 1; i < (n / m)+2; i++) {
for (int l = 1; l < m+1; l++) {
int a = ran.nextInt(100);
int b = ran.nextInt(100);
int c = ran.nextInt(4);
int k=l+(i-1)*m;
if(k>n||(s1[i-1][l-1]==a&&s2[i-1][l-1]==b&&s3[i-1][l-1]==c))
break;
if (c == 0) {
System.out.print(k+ ".");
System.out.print(a + "+" + b + "= ");
s1[i-1][l-1]=a;
s2[i-1][l-1]=b;
s3[i-1][l-1]=c;
} else if (c == 1 && a >= b) {
System.out.print(k + ".");
System.out.print(a + "-" + b + "= ");
s1[i-1][l-1]=a;
s2[i-1][l-1]=b;
s3[i-1][l-1]=c;
} else if (c == 2 && a * b < 100) {
System.out.print(k + ".");
System.out.print(a + "*" + b + "= ");
s1[i-1][l-1]=a;
s2[i-1][l-1]=b;
s3[i-1][l-1]=c;
} else if (c == 3 && b != 0 && a % b == 0) {
System.out.print(k + ".");
System.out.print(a + "/" + b + "= ");
s1[i-1][l-1]=a;
s2[i-1][l-1]=b;
s3[i-1][l-1]=c;
} else {
l--;
}
}
System.out.println("");
}
}
}