ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

二柱子四则运算B级

2020-12-19 20:04:02  阅读:150  来源: 互联网

标签:柱子 Random java package int 四则运算 Repeat public


package 测试;
import java.util.*;
public class Addition 
{
    
    public static void Repeat(int a[ ],int b[ ],int c[ ],int n)
    {
        Random rand=new Random( );
        int i,j;
        for(i=0;i<n;i++)
        {
            for(j=0;j<i;j++)
            {
                while(a[j]==a[i]&&b[j]==b[i]&&c[j]==c[i])
                {
                    a[i]=rand.nextInt(100);
                    break;
                }
            }
        }
    }
    
    public static void RandomInt(int a[ ],int b[ ],int c[ ],int n,int m,int d)
    {
        int i,temp;
        Random rand=new Random( );
        for(i=0;i<n;i++)
        {
            a[i]=rand.nextInt(d-m)+(m);
            b[i]=rand.nextInt(d-m)+(m);
            c[i]=rand.nextInt(4);
            if(a[i]<b[i])
            {
                temp=a[i];
                a[i]=b[i];
                b[i]=temp;
            }
            switch(c[i])
            {
            case 0:System.out.print(i+1+" "+a[i]+"+"+b[i]+"="+'\n');break;
            case 1:System.out.print(i+1+" "+a[i]+"-"+b[i]+"="+'\n');break;
            case 2:System.out.print(i+1+" "+a[i]+"×"+b[i]+"="+'\n');break;
            case 3:System.out.print(i+1+" "+a[i]+"/"+b[i]+"="+'\n');break;
            }
        }
    }
    
    public static void Exem(int a[ ],int b[ ],int c[ ],int error[ ],int n)
    {
        int i,g,h=0,k=0;
        int []count2=new int[100];
        int d[]=new int[100];
        Scanner scan=new Scanner(System.in);
        System.out.print("欢迎来到答题系统!"+'\n');
        for(i=0;i<n;i++)
        {
            switch(c[i])
            {
            case 0:
            {
                System.out.print(i+1+" "+a[i]+"+"+b[i]+"=");
                g=scan.nextInt( );
                if(g==a[i]+b[i])
                {
                    h++;
                    System.out.print("回答正确!"+'\n');
                }
                else
                {
                    count2[i]++;
                    System.out.print("回答错误!"+"   "+count2[i]+'\n');
                    error[k]=i;
                    k++;
                }
            }break;
            case 1:
            {
                System.out.print(i+1+" "+a[i]+"-"+b[i]+"=");
                g=scan.nextInt( );
                if(g==a[i]-b[i])
                {
                    h++;
                    System.out.print("回答正确!"+'\n');
                }
                else
                {
                    count2[i]++;
                    System.out.print("回答错误!"+"   "+count2[i]+'\n');
                    error[k]=i;
                    k++;
                }
            }break;
            case 2:
            {
                System.out.print(i+1+" "+a[i]+"*"+b[i]+"=");
                g=scan.nextInt( );
                if(g==a[i]*b[i])
                {
                    h++;
                    System.out.print("回答正确!"+'\n');
                }
                else
                {
                    count2[i]++;
                    System.out.print("回答错误!"+"   "+count2[i]+'\n');
                    error[k]=i;
                    k++;
                }
            }break;
            case 3:
                {
                    System.out.print(i+1+" "+a[i]+"/"+b[i]+"=");
                    g=scan.nextInt( );
                    if(g==a[i]/b[i])
                    {
                        h++;
                        System.out.print("回答正确!"+'\n');
                    }
                    else
                    {
                        count2[i]++;
                        System.out.print("回答错误!"+"   "+count2[i]+'\n');
                        error[k]=i;
                        k++;
                    }
                }break;
            }
        }
        System.out.print("正确率:"+(double)h/n+'\n');
        if((double)h/n!=1)
        {
            System.out.print("错题如下:"+'\n');
            Error(a,b,c,error,k,d,count2);
        }
        else
        {
            System.out.print("你真棒!全对了!"+'\n');
        }
    }
    
    static void Error(int a[ ],int b[ ],int c[ ],int d[ ],int n,int see[ ],int count2[ ])
    {
        int count=0,i,g;
        Scanner scan=new Scanner(System.in);
        for(i=0;i<n;i++)
        {
            switch(c[d[i]])
            {
            case 0:
            {
                System.out.print(d[i]+1+" "+a[d[i]]+"+"+b[d[i]]+"=");
                g=scan.nextInt( );
                if(g!=a[d[i]]+b[d[i]])
                {
                    count2[i]++;
                    System.out.print("回答错误!"+"   "+count2[i]+'\n');
                    see[count]=d[i];
                    d[count]=see[count];
                    count++;
                }
                else
                {
                    System.out.print("回答正确!"+'\n');
                }
            }break;
            case 1:
            {
                System.out.print(d[i]+1+" "+a[d[i]]+"-"+b[d[i]]+"=");
                g=scan.nextInt( );
                if(g!=a[d[i]]-b[d[i]])
                {
                    count2[i]++;
                    System.out.print("回答错误!"+"   "+count2[i]+'\n');
                    see[count]=d[i];
                    d[count]=see[count];
                    count++;
                }
                else
                {
                    System.out.print("回答正确!"+'\n');
                }
            }break;
            case 2:
            {
                System.out.print(d[i]+1+" "+a[d[i]]+"*"+b[d[i]]+"=");
                g=scan.nextInt( );
                if(g!=a[d[i]]*b[d[i]])
                {
                    count2[i]++;
                    System.out.print("回答错误!"+"   "+count2[i]+'\n');
                    see[count]=d[i];
                    d[count]=see[count];
                    count++;
                }
                else
                {
                    System.out.print("回答正确!"+'\n');
                }
            }break;
            case 3:
                {
                    System.out.print(d[i]+1+" "+a[d[i]]+"/"+b[d[i]]+"=");
                    g=scan.nextInt( );
                    if(g!=a[d[i]]/b[d[i]])
                    {
                        count2[i]++;
                        System.out.print("回答错误!"+"   "+count2[i]+'\n');
                        see[count]=d[i];
                        d[count]=see[count];
                        count++;
                    }
                    else
                    {
                        System.out.print("回答正确!"+'\n');
                    }
                }break;
            }
        }
        if(count!=0)
        {
            System.out.print("还有错题哦,小朋友,再做做吧!"+'\n');
             Error(a,b,c,d,count,see,count2);
        }
        
    }
    public static void main(String[] args) 
    {
        // TODO 自动生成的方法存根
        int n,i,m,d;
        int [ ]a=new int[100];
        int [ ]b=new int[100];
        int [ ]c=new int[100];
        int [ ]er1=new int[100];
        Scanner scan=new Scanner(System.in);
        System.out.print("Please print the number:");
        n=scan.nextInt( );
        System.out.print("请输入操作数范围:");
        m=scan.nextInt( );
        d=scan.nextInt( );
        RandomInt(a,b,c,n,m,d);
        Repeat(a,b,c,n);
        Exem(a,b,c,er1,n);
        System.out.print('\n');
    }
}

 

标签:柱子,Random,java,package,int,四则运算,Repeat,public
来源: https://www.cnblogs.com/liuyang-cn/p/14160774.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有