zoukankan      html  css  js  c++  java
  • 10.13

    package szys;

    import java.util.Random;
    import java.util.Scanner;
    public class Test2 {

    public static void main(String[] args) {

    Scanner scanner=new Scanner(System.in);
    System.out.println("请输入出题题数:");
    int sum = scanner.nextInt();
    //int c=scanner.nextInt();
    /*int sum = 0,c = 0;
    sum(sum);
    fanwei(c);*/
    int[] arr1=new int[sum*2];
    int[] xuhao=new int[sum];
    int[] shu1=new int[sum];
    int[] fuhao=new int[4];
    int[] shu2=new int[sum];
    randomArr(arr1);
    /*for(int i=0;i<rand.length;i++) {
    System.out.println(rand[i]);
    }*/

    System.out.println("是否出现乘除运算,是输入1,否输入0");
    //Scanner scanner=new Scanner(System.in);
    int x=scanner.nextInt();
    int k=0,m=0,right=0;

    switch(x) {
    case 0:
    //String[] operate=new String[]{"+","-"};
    Random rand=new Random();
    for(int i=0;i<arr1.length;i=i+2){
    int rand1=rand.nextInt(2);
    if(rand1==0) {
    System.out.println(k+1+". "+arr1[i]+'+'+arr1[i+1]+"=");

    int jieguo=scanner.nextInt();

    if(arr1[i]+arr1[i+1]==jieguo) {
    System.out.println("正确!");right++;
    }
    else {
    System.out.println("错误,已记录在错题本");xuhao[m]=k+1;shu1[m]=arr1[i];fuhao[m]=0;shu2[m]=arr1[i+1]; m++; }

    }

    else if(rand1==1) {
    System.out.println(k+1+". "+arr1[i]+'-'+arr1[i+1]+"=");

    int jieguo=scanner.nextInt();

    if(arr1[i]-arr1[i+1]==jieguo) {

    System.out.println("正确!");right++;
    }
    else {
    System.out.println("错误,已记录在错题本");xuhao[m]=k+1;shu1[m]=arr1[i];fuhao[m]=1;shu2[m]=arr1[i+1]; m++; }
    }

    ++k;}

    break;

    case 1:

    Random rand2=new Random();

    for(int i=0;i<arr1.length;i=i+2){
    int rand1=rand2.nextInt(4);

    if(rand1==0) {
    System.out.println(k+1+". "+arr1[i]+'+'+arr1[i+1]+"=");
    int jieguo=scanner.nextInt();

    if(arr1[i]+arr1[i+1]==jieguo) {
    System.out.println("正确!");right++;
    }
    else {
    System.out.println("错误,已记录在错题本");xuhao[m]=k+1;shu1[m]=arr1[i];fuhao[m]=0;shu2[m]=arr1[i+1]; m++; }

    }
    else if(rand1==1) {
    System.out.println(k+1+". "+arr1[i]+'-'+arr1[i+1]+"=");
    int jieguo=scanner.nextInt();
    if(arr1[i]-arr1[i+1]==jieguo) {
    System.out.println("正确!");right++;
    }
    else {
    System.out.println("错误,已记录在错题本");xuhao[m]=k+1;shu1[m]=arr1[i];fuhao[m]=1;shu2[m]=arr1[i+1]; m++; }
    }
    else if(rand1==2) {
    System.out.println(k+1+". "+arr1[i]+'*'+arr1[i+1]+"=");
    int jieguo=scanner.nextInt();
    if(arr1[i]*arr1[i+1]==jieguo) {
    System.out.println("正确!");right++;
    }
    else {
    System.out.println("错误,已记录在错题本");xuhao[m]=k+1;shu1[m]=arr1[i];fuhao[m]=2;shu2[m]=arr1[i+1]; m++; }
    }
    else if(rand1==3) {
    System.out.println(k+1+". "+arr1[i]+'/'+arr1[i+1]+"=");
    int jieguo=scanner.nextInt();
    if(arr1[i]/arr1[i+1]==jieguo) {
    System.out.println("正确!");right++;
    }
    else {
    System.out.println("错误,已记录在错题本");xuhao[m]=k+1;shu1[m]=arr1[i];fuhao[m]=3;shu2[m]=arr1[i+1]; m++; }
    }
    ++k;}
    break;
    }
    System.out.println("正确率:"+(right*100)/sum+"%");

    System.out.println("是否重做错题?是输入1,否输入0");
    int cout=scanner.nextInt();

    while(cout==1) {
    String[] operate=new String[]{"+","-","*","/"};

    for(int i=0;i<m;i++) {
    //System.out.println(xuhao[i]+'.');
    System.out.println(shu1[i]+operate[fuhao[i]]+shu2[i]+'=');
    int jieguo1=scanner.nextInt();
    if(fuhao[i]==0) {
    while(jieguo1!=shu1[i]+shu2[i]) {
    System.out.println("错误,请重新输入答案:");
    jieguo1=scanner.nextInt();
    }
    System.out.println("正确");
    }
    else if(fuhao[i]==1) {
    while(jieguo1!=shu1[i]-shu2[i]) {
    System.out.println("错误,请重新输入答案:");
    jieguo1=scanner.nextInt();
    }
    System.out.println("正确");
    }
    else if(fuhao[i]==2) {
    while(jieguo1!=shu1[i]*shu2[i]) {
    System.out.println("错误,请重新输入答案:");
    jieguo1=scanner.nextInt();
    }
    System.out.println("正确");
    }
    else if(fuhao[i]==3) {
    while(jieguo1!=shu1[i]/shu2[i]) {
    System.out.println("错误,请重新输入答案:");
    jieguo1=scanner.nextInt();
    }
    System.out.println("正确");
    }
    }
    System.out.println();
    System.out.println();
    System.out.println("已结束!!!");
    break;
    }
    if(cout==0) {System.out.println("已退出!!!");}
    }



    public static int[] randomArr(int[] arr) {
    Random rd = new Random();
    for (int i = 0; i < arr.length; i++) {
    int count = 0;
    // arr[i]=rd.nextInt(10)+1;
    int temp = rd.nextInt(100);

    for (int j = 0; j < arr.length; j++) {
    if (arr[j] == temp) {
    count++;

    }
    }if (count>0){

    i--;

    }else{
    arr[i] = temp;
    }
    }
    return arr;
    }

    }

  • 相关阅读:
    kettle用户手册(7:变量)
    kettle用户手册(3:创建一个数据库链接)
    PDI的steps:(4:Add sequence)
    kettle用户手册(2:创建一个转换或者job)
    vmware vsphere 5虚拟数据中心构建指南(一)
    PDI的step:(1:abort)
    MongoDB在CentOS下的安装(二次修改)
    Cent OS 5.6下安装MongoDB教程
    CentOS5.6安装DNS的Bind服务器
    芒果知识补充(1)mongodb 单机的备份与恢复
  • 原文地址:https://www.cnblogs.com/zhaoyuxiao000/p/13812179.html
Copyright © 2011-2022 走看看