四则运算---根据用户要求输出计算题源代码

import java.util.Scanner;
public class Test {
 public static void main(String[] args) {
  Scanner scan=new Scanner(System.in);
  System.out.println("请输入题目的数量:");
  int n=scan.nextInt();
  System.out.println("请输入一行的题目数量:");
  int m=scan.nextInt();
  String [] str2=new String [n];
  for(int q=0;q<n;q++) {
   str2[q]=null;
  }
  for(int i=1;i<n+1;i++) {
   int a=(int) (1+Math.random()*(99-1+1));
   int b=(int) (1+Math.random()*(99-1+1));
   int x=(int) (1+Math.random()*(4-1+1));
   boolean t1=true;
   boolean t2=true;
   boolean t3=true;
   boolean t4=true;
   String str1 = null;
   switch(x) {
   case 1:
    str1="+";
    break;
   case 2:
    str1="-";
    if(a<b) {
     t1=false;
     i--;
    }
    break;
   case 3:
    str1="*";
    break;
   case 4:
    str1="/";
    if(a%b!=0) {
     t2=false;
     i--;
    }
    break;
   }
   if(i%m==0) {
    t3=false;
   }
   if(t1&&t2) {
    if(t3) {
     System.out.print("第"+i+"道题 "+a+str1+b+"=      ");
    }
    else {
     System.out.println("第"+i+"道题 "+a+str1+b+"=      ");
    }
   } 
  }
 }
}
原文地址:https://www.cnblogs.com/xhj1074376195/p/11551442.html