• Java学习


    学习内容:课堂测试二阶段二

     代码示例:

    import java.util.Random;
    import java.util.Scanner;

    public class Test2to2 {

    public static void answer() {//在线答题
    int num1;
    int num2;
    double sum;
    int number1[]=new int[100];
    int number2[]=new int[100];
    int number3[]=new int[100];
    int number4[]=new int[100];
    int number5[]=new int[100];
    int number6[]=new int[100];
    int number7[]=new int[100];
    int number8[]=new int[100];
    int i,j,choice,rightnum=0,n1=0,n2=0,n3=0,n4=0;
    char c;
    double accurary;//正确率
    char[] operator=new char[]{'+','-','*','/'};
    Random rand = new Random();
    for(i=1;i<=30;i++) {
    j=rand.nextInt(4);
    c=operator[j];
    num1=rand.nextInt(100);
    num2=rand.nextInt(100);
    Scanner sc=new Scanner(System.in);
    if(c=='+') {
    int result;
    sum=num1+num2;
    System.out.print("第"+i+"道题为:");
    System.out.println(num1+"+"+num2+"=");
    System.out.println("请输入计算结果:");
    result=sc.nextInt();
    System.out.println("答题结果为:"+num1+"+"+num2+"="+result);
    if(result==sum) {
    rightnum+=1;
    }
    else {
    n1+=1;
    number1[n1]=num1;
    number2[n1]=num2;
    }
    }
    else if(c=='-') {
    int result;
    System.out.print("第"+i+"道题为:");
    System.out.println(num1+"-"+num2+"=");
    sum=num1-num2;
    System.out.println("请输入计算结果:");
    result=sc.nextInt();
    System.out.println("答题结果为:"+num1+"-"+num2+"="+result);
    if(result==sum) {
    rightnum+=1;
    }
    else {
    n2+=1;
    number3[n2]=num1;
    number4[n2]=num2;
    }
    }
    else if(c=='*') {
    int result;
    System.out.print("第"+i+"道题为:");
    System.out.println(num1+"*"+num2+"=");
    sum=num1*num2;
    System.out.println("请输入计算结果:");
    result=sc.nextInt();
    System.out.println("答题结果为:"+num1+"*"+num2+"="+result);
    if(result==sum) {
    rightnum+=1;
    }
    else {
    n3+=1;
    number5[n3]=num1;
    number6[n3]=num2;
    }
    }
    else if(c=='/') {
    int result;
    System.out.print("第"+i+"道题为:");
    System.out.println(num1+"/"+num2+"=");
    sum=(double)num1/(double)num2;
    System.out.println("请输入计算结果:");
    result=sc.nextInt();
    System.out.println("答题结果为:"+num1+"/"+num2+"="+result);
    if(result==sum) {
    rightnum+=1;
    }
    else {
    n4+=1;
    number7[n4]=num1;
    number8[n4]=num2;
    }
    }
    }
    accurary=(double)rightnum/30.0;
    System.out.println("您的正确率为:"+accurary*100+"%");
    System.out.println("您的错题集为:");
    for(i=1;i<=n1;i++) {
    System.out.println(number1[i]+"+"+number2[i]+"=");
    }
    for(i=1;i<=n2;i++) {
    System.out.println(number3[i]+"-"+number4[i]+"=");
    }
    for(i=1;i<=n3;i++) {
    System.out.println(number5[i]+"*"+number6[i]+"=");
    }
    for(i=1;i<=n4;i++) {
    System.out.println(number7[i]+"/"+number8[i]+"=");
    }
    do {
    System.out.println("错题重练请按1,结束练习请按0:");
    Scanner sc=new Scanner(System.in);
    choice=sc.nextInt();
    if(choice==1) {
    for(i=1;i<=n1;i++) {
    double result;
    int wrongnum=1;
    System.out.println(number1[i]+"+"+number2[i]+"=");
    sum=number1[i]+number2[i];
    System.out.println("请输入计算结果:");
    result=sc.nextDouble();
    System.out.println("答题结果为:"+number1[i]+"+"+number2[i]+"="+result);
    if(result!=sum) {
    wrongnum+=1;
    System.out.println("回答错误,该题错误次数为"+wrongnum);
    }
    else {
    System.out.println("回答正确,本题错误次数为:"+wrongnum);
    }
    }
    for(i=1;i<=n2;i++) {
    double result;
    int wrongnum=1;
    System.out.println(number3[i]+"-"+number4[i]+"=");
    sum=number1[i]-number2[i];
    System.out.println("请输入计算结果:");
    result=sc.nextDouble();
    System.out.println("答题结果为:"+number3[i]+"-"+number4[i]+"="+result);
    if(result!=sum) {
    wrongnum+=1;
    System.out.println("回答错误,该题错误次数为"+wrongnum);
    }
    else {
    System.out.println("回答正确,本题错误次数为:"+wrongnum);
    }
    }
    for(i=1;i<=n3;i++) {
    double result;
    int wrongnum=1;
    System.out.println(number5[i]+"*"+number6[i]+"=");
    sum=number1[i]*number2[i];
    System.out.println("请输入计算结果:");
    result=sc.nextDouble();
    System.out.println("答题结果为:"+number5[i]+"*"+number6[i]+"="+result);
    if(result!=sum) {
    wrongnum+=1;
    System.out.println("回答错误,该题错误次数为"+wrongnum);
    }
    else {
    System.out.println("回答正确,本题错误次数为:"+wrongnum);
    }
    }
    for(i=1;i<=n4;i++) {
    double result;
    int wrongnum=1;
    System.out.println(number7[i]+"/"+number8[i]+"=");
    sum=(double)number1[i]/(double)number2[i];
    System.out.println("请输入计算结果:");
    result=sc.nextDouble();
    System.out.println("答题结果为:"+number7[i]+"/"+number8[i]+"="+result);
    if(result!=sum) {
    wrongnum+=1;
    System.out.println("回答错误,该题错误次数为"+wrongnum);
    }
    else {
    System.out.println("回答正确,本题错误次数为:"+wrongnum);
    }
    }
    }
    }while(choice==1);
    }

    public static void main(String[] args) {
    answer();
    }
    }

    明天任务:课堂测试二阶段三

  • 相关阅读:
    JavaScript定时器及相关面试题
    单线程JavaScript
    webpack基础入门
    SQL Server 服务器器信息备份(二)--权限备份
    SQL Server 服务器器信息备份(一)--login新建脚本备份
    Raid与DAN、SAN、NAS基础
    AlwaysOn可用性组功能测试(三)--其他测试
    AlwaysOn可用性组功能测试(二)--SQL Server群集故障转移对AlwaysOn可用性组的影响
    AlwaysOn可用性组功能测试(一)--AlwaysOn故障转移测试
    AlwaysOn可用性组测试环境安装与配置(一)--SQL群集环境搭建
  • 原文地址:https://www.cnblogs.com/zyj3955/p/13779523.html
Copyright © 2020-2023  润新知