每日日报2020 10/12

昨天的代码写到一半没写了,就没往上面写了,主要是难受。

今天把它写完了,谢谢上帝让我还活着。

package please;

import java.util.Random;
import java.util.Scanner;
public class Rand1 {
public static void check(int e, int d1[], int d2[]) {

}
}
}
}

public static void manage(int e, int d1[], int d2[]) {
int a, b;
for (int i = 0; i < e; i++) {
Random r = new Random();
a = r.nextInt(100) + 1;
b = r.nextInt(100) + 1;
d1[i] = a;
d2[i] = b;
}

}
public static void jisuan(int x,int e, int d1[], int d2[],int d3[]) {
int [] number;
int[] number1= new int [10000];
int n=0;
Scanner in=new Scanner(System.in);
Random r = new Random();
if (x == 0) {
for(int i=0;i<e;i++) {
switch (r.nextInt(2) + 1) {
case 1:
d3[i]=d1[i]+d2[i];
System.out.println((i + 1) + ". " + d1[i] + "+" + d2[i] + "=");
number1[i]=in.nextInt();
if(number1[i]!=d3[i]) {
n++;
}
break;
case 2:
d3[i]=d1[i]-d2[i];
System.out.println((i + 1) + ". " + d1[i] + "-" + d2[i] + "=");
number1[i]=in.nextInt();
if(number1[i]!=d3[i]) {
n++;
}
break;
}
}
System.out.println(n);
}
else
{
if(x==1) {
for(int i=0;i<e;i++) {
switch (r.nextInt(4) + 1) {
case 1:
d3[i]=d1[i]+d2[i];
System.out.println((i + 1) + ". " + d1[i] + "+" + d2[i] + "=");
number1[i]=in.nextInt();
if(number1[i]!=d3[i]) {
n++;
}
break;
case 2:
d3[i]=d1[i]-d2[i];
System.out.println((i + 1) + ". " + d1[i] + "-" + d2[i] + "=");
number1[i]=in.nextInt();
if(number1[i]!=d3[i]) {
n++;
}
break;
case 3:
d3[i]=d1[i]*d2[i];
System.out.println((i + 1) + ". " + d1[i] + "*" + d2[i] + "=");
number1[i]=in.nextInt();
if(number1[i]!=d3[i]) {
n++;
}
break;
case 4:
d3[i]=d1[i]/d2[i];
System.out.println((i + 1) + ". " + d1[i] + "/" + d2[i] + "=");
number1[i]=in.nextInt();
if(number1[i]!=d3[i]) {
n++;
}
break;
}
}
System.out.println(n);
}
}




}
public static void managenumber(int y) {
switch(y) {
case 2:break;
case 3:
}
}

public static void main(String[] args) {
System.out.println("请输入你要生成题目的数量:");
int e;
Scanner number = new Scanner(System.in);
e = number.nextInt();
System.out.println("加减运算请输入0 加减乘除运算请输入1:");
Scanner number2 = new Scanner(System.in);
int x;
x = number2.nextInt();
System.out.println("请输入你要的操作数个数(本程序只接受2~4之间的操作数)");
int y;
Scanner number3=new Scanner(System.in);
y=number3.nextInt();
int[] result;
int result1[] = new int[10000];
int result2[] = new int[10000];
int result3[] = new int[10000];
manage(e, result1, result2);
check(e,result1,result2);
jisuan(x,e,result1,result2,result3);
}
}

 

package please;

import java.util.*;
import static java.lang.System.*;
public class Rand2
{
static public double[] out_=new double[1000];
public static void main(String[] args)
{

int operate,sum_shizi,range=0;
Scanner in=new Scanner(System.in);
out.println("输入操作数的个数(大于1)");
operate=in.nextInt();//操作数个数
out.println("输入每一个操作数的数据范围");
range=in.nextInt();//每个项的范围
out.println("输入出题总数");
sum_shizi=in.nextInt();//出题总数
answer(operate,range,sum_shizi);
}

static String Random(int range,int operate,int firm)//随机生成计算式,第一个参数是每个数的范围,第二个参数是操作数
{
int[] item=new int[operate];//记录算式每一项
String str=new String();//储存计算式
String[] choice={"+","-","*","/"};
for(int i=0;i<operate;i++)
item[i]=(int)(Math.random()*range+1);
out_[firm]=item[0];
str +=item[0];
int opChoice=(int)(Math.random()*10/3);
for(int i=1;i<operate;i++) {
opChoice=(int)(Math.random()*10/3);//运算符的选择
str+=choice[opChoice];
str += item[i];
output(item,opChoice,i,firm);//计算结果
if(i!=operate-1) {
//最后不加最后一个运算符
str += choice[opChoice];
}
}
str+="=";
return str;
}

static void output(int[] item,int opChoice,int i,int firm)//记录每个式子的结果
{
switch (opChoice){
case 0:
out_[firm]+=item[i];
break;
case 1:
out_[firm]-=item[i];
break;
case 2:
out_[firm]*=item[i];
break;
case 3:
out_[firm]/=item[i];
break;
}
}

static void judgeAndcreate(String[] Sum,int range,int operate,int sum_shizi)//查重和生成计算式
{
Sum[0]=Random(range,operate,0);
String next=null;
int i=0;//保存新生成的算式的储存下标
int j=0;//指向之前的算式的下标
while(i<sum_shizi)
{
next=Random(range,operate,i+1);;
boolean sat=true;//新算式不重复为false,重复为true
j=0;
while(sat) {
while(j<=i) {//判断与之前的算式是否有重复
if(!Sum[j].equals(next))
j++;
else
break;
}
if(j<=i) {//在之前声明的算式中有重复,生成新的计算式,再次开始
j=0;
next=Random(range,operate,i+1);;
}
else
sat=false;
}
sat=true;
Sum[++i]=next;
}
}

static void print(int operate,int range,int sum_shizi)//打印算式
{
String[] Sum=new String[sum_shizi+1];
judgeAndcreate(Sum,range,operate,sum_shizi);
int i=0;
while(i<sum_shizi){
out.println(i+1+":"+Sum[i]);
++i;
}
}

static void answer(int operate,int range,int sum_shizi){
Scanner in=new Scanner(System.in);
String[] Sum=new String[sum_shizi+1];
String[] Sum1=new String[sum_shizi];
judgeAndcreate(Sum,range,operate,sum_shizi);
double result=0;
double right=0;
double wrong=0;
double result2=0;
int i=0;
while(i<sum_shizi){
out.println(i+1+":"+Sum[i]);
out.println("请输入结果:");
result=in.nextDouble();
if(result==out_[i]){
out.println("正确");
right++;
}
else{
int t=0;
out.println("错误");
wrong++;
Sum1[t]=Sum[i];
t++;
}
i++;
}
out.println("正确率:"+(right/sum_shizi)*100+"%");
out.println("错题数目:"+wrong);

out.println("If you want open the error books?");
out.println("1:Yes");
out.println("2.NO");

int num=in.nextInt();

if(num==1) {
for(int t=0;t<wrong;t++)
{
System.out.println((t+1)+":"+Sum1[t]);
}


out.println("If you want to write again?");
out.println("1:Yes");
out.println("2.NO");
int num2=in.nextInt();
if(num2==1)
{
for(int n=0;n<wrong;n++)
{
result2=in.nextInt();
}
}
else
{
out.println("You may just want to do it again.");
for(int n=0;n<wrong;n++)
{
result2=in.nextInt();
}
}
}
else {
out.println("GOODBYE!");
}

}
}

 

package please;
import java.util.Random;
public class random {
public static void main(String[] args) {
Random rand=new Random();
Random rand1=new Random();
Random rand2=new Random();
for(int i=0;i<=30;i++) {
int m=rand.nextInt(4);
switch(m)
{
case 0:{int number=rand1.nextInt(100);int number2=rand2.nextInt(100);System.out.println(number+"+"+number2+"=");}
case 1:{int number=rand1.nextInt(100);int number2=rand2.nextInt(100);System.out.println(number+"-"+number2+"=");}
case 2:{int number=rand1.nextInt(100);int number2=rand2.nextInt(100);System.out.println(number+"*"+number2+"=");}
case 3:{int number=rand1.nextInt(100);int number2=rand2.nextInt(100);System.out.println(number+"/"+number2+"=");}
}
}

}

}

 

posted @ 2020-10-12 22:13  宋振兴  阅读(50)  评论(0编辑  收藏  举报