package 测试1; import java.util.Scanner; import java.util.Random; public class operations { public static String b; public static int j=0; public static int u=0; public String c="+"; public String d="-"; public String e="*"; public String f="/"; public static int num1; public static int num2; int z[]=new int[1000000]; int x[]=new int[1000000]; String v[]=new String[1000000]; void fuzhi() { num1=(int)(Math.random()*100); num2=(int)(Math.random()*100); } void fuhao() { int a=(int)(Math.random()*100); if(0<a&&a<=25) { b="+"; } else if(25<a&&a<=50) { b="-"; } else if(50<a&&a<=75) { b="*"; } else if(75<a&&a<100) { b="/"; } } void jia() { operations A=new operations(); A.fuzhi(); if(b.equals(c)) { System.out.print(operations.num1); System.out.print(b); System.out.print(operations.num2); System.out.println("="); } } void jian() { operations A=new operations(); A.fuzhi(); if(b.equals(d)) { if(num1>=num2) { System.out.print(operations.num1); System.out.print(b); System.out.print(operations.num2); System.out.println("="); } else { System.out.print(operations.num2); System.out.print(b); System.out.print(operations.num1); System.out.println("="); } } } void cheng() { operations A=new operations(); A.fuzhi(); if(b.equals(e)) { double q=num1*num2; if(q<100) { System.out.print(operations.num1); System.out.print(b); System.out.print(operations.num2); System.out.println("="); } else { A.cheng(); } } } void chu() { operations A=new operations(); A.fuzhi(); if(b.equals(f)) { if(num2!=0) { if(num1%num2==0) { System.out.print(operations.num1); System.out.print(b); System.out.print(operations.num2); System.out.println("="); } else { A.chu(); } } else { A.chu(); } } } void chongfu() { operations A=new operations(); z[j]=A.num1; x[j]=A.num2; v[j]=A.b; j++; } void yanzheng() { operations A=new operations(); for(int i=0;i<j;i++) { if((z[i]==z[j])&&(x[i]==x[j])&&(v[i].equals(v[j]))) { A.kaishi(); } } } void kaishi() { operations A=new operations(); for(int i=0;i<u;i++) { A.fuhao(); System.out.print(i+1); System.out.print(". "); A.jia(); A.jian(); A.cheng(); A.chu(); } } public static void main(String[] args) { operations A=new operations(); Scanner input=new Scanner(System.in); System.out.println("请输入想得到的个数"); int t=input.nextInt(); u=t; for(int i=0;i<u;i++) { A.fuhao(); System.out.print(i+1); System.out.print(". "); A.jia(); A.jian(); A.cheng(); A.chu(); A.chongfu(); if(i>1) { A.yanzheng();} } } }
实现随机产生100以内的四则运算,并验证是否重复