课堂测试

给你一囗甜甜゛ 提交于 2019-11-30 03:34:13

课堂测试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--;
   }
  }
 }
}
课堂测试2:
import java.util.Scanner;
import java.util.Random;
public class Sappp {
 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("");
  }
 }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!