• 小学数学测试题demo


    目前只实现了重新出题和显示答案两个功能,其他功能以后完善

    部分代码

    package com.example.uidemo;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.os.Bundle;
    import android.view.*;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.TextView;
    
    import java.util.Random;
    
    public class MainActivity extends AppCompatActivity {
        TextView textView;
        Button button3,button4;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            textView=findViewById(R.id.textView);
            button3=findViewById(R.id.button3);
            button4=findViewById(R.id.button4);
    
            Random r = new Random();
            int a=0;
            int d = 30;
            String s[] = new String[d];
            String b[]=new String[d];
    
            for (int i = 0; i < d; i++) {
                int ran1 = r.nextInt(100000) + 1;
                int ran2 = r.nextInt(100) + 1;
                while (ran1 < 10000 || ran2 < 11 || ran2 == 0 || ran1 % ran2 != 0 || ran1 <= ran2 || ran2 % 10 == 0) {
                    ran1 = r.nextInt(100000) + 1;
                    ran2 = r.nextInt(100) + 1;
    
                }
                String s1 = Integer.toString(ran1);
                String s2= Integer.toString(ran2);
                String s3 = Integer.toString(ran1 / ran2);
    
                if(s3.length()==3) continue;
                //System.out.println("---"+s3.substring(3, 4)+"---");
                if(a!=9) {
                    s[i] = a + 1 +  ",      " + s1.substring(0, 3) + "." + s1.substring(3, 5) + " % " + s2.substring(0, 1) + "." + s2.substring(1, 2) + " = "
                            + s3.substring(0, 3) + "." + s3.substring(3, 4);
                    b[i] =  a + 1 + ",      " + s1.substring(0, 3) + "." + s1.substring(3, 5) + " % " + s2.substring(0, 1) + "." + s2.substring(1, 2) + " = ";
                }
                else {
                    s[i] =  a + 1 + ",    " + s1.substring(0, 3) + "." + s1.substring(3, 5) + " % " + s2.substring(0, 1) + "." + s2.substring(1, 2) + " = "
                            + s3.substring(0, 3) + "." + s3.substring(3, 4);
                    b[i] =  a + 1 + ",    " + s1.substring(0, 3) + "." + s1.substring(3, 5) + " % " + s2.substring(0, 1) + "." + s2.substring(1, 2) + " = ";
    
                }
    
                a++;
                if(a==10) break;
            }
            String abc="";
            String da = "answer";
            String ab="";
            a=0;
            if (da.equals("answer")) {
                for (int i = 0; i < d; ++i) {
                    if(s[i]!=null) {
                        ab+=s[i]+"
    ";
                        abc+=b[i]+"
    ";
                    }
    
                }
    
            }
            textView.setText(abc);
    
            final String finalAbc = abc;
            final String finalAb = ab;
            button3.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View view) {
                    textView.setText(finalAb);
                }
    
    
            });
            button4.setOnClickListener(new View.OnClickListener(){
                @Override
                public void onClick(View view) {
                    abcd();
                }
    
    
            });
    
    
    
    
            }
    
            public void abcd(){
                textView=findViewById(R.id.textView);
                button3=findViewById(R.id.button3);
                button4=findViewById(R.id.button4);
    
                Random r = new Random();
                int a=0;
                int d = 30;
                String s[] = new String[d];
                String b[]=new String[d];
    
                for (int i = 0; i < d; i++) {
                    int ran1 = r.nextInt(100000) + 1;
                    int ran2 = r.nextInt(100) + 1;
                    while (ran1 < 10000 || ran2 < 11 || ran2 == 0 || ran1 % ran2 != 0 || ran1 <= ran2 || ran2 % 10 == 0) {
                        ran1 = r.nextInt(100000) + 1;
                        ran2 = r.nextInt(100) + 1;
    
                    }
                    String s1 = Integer.toString(ran1);
                    String s2= Integer.toString(ran2);
                    String s3 = Integer.toString(ran1 / ran2);
    
                    if(s3.length()==3) continue;
                    //System.out.println("---"+s3.substring(3, 4)+"---");
                    if(a!=9) {
                        s[i] =  a + 1 + ",      " + s1.substring(0, 3) + "." + s1.substring(3, 5) + " % " + s2.substring(0, 1) + "." + s2.substring(1, 2) + " = "
                                + s3.substring(0, 3) + "." + s3.substring(3, 4);
                        b[i] =  a + 1 + ",      " + s1.substring(0, 3) + "." + s1.substring(3, 5) + " % " + s2.substring(0, 1) + "." + s2.substring(1, 2) + " = ";
                    }
                    else {
                        s[i] =  a + 1 + ",    " + s1.substring(0, 3) + "." + s1.substring(3, 5) + " % " + s2.substring(0, 1) + "." + s2.substring(1, 2) + " = "
                                + s3.substring(0, 3) + "." + s3.substring(3, 4);
                        b[i] =  a + 1 + ",    " + s1.substring(0, 3) + "." + s1.substring(3, 5) + " % " + s2.substring(0, 1) + "." + s2.substring(1, 2) + " = ";
    
                    }
    
                    a++;
                    if(a==10) break;
                }
                String abc="";
                String da = "answer";
                String ab="";
                a=0;
                if (da.equals("answer")) {
                    for (int i = 0; i < d; ++i) {
                        if(s[i]!=null) {
                            ab+=s[i]+"
    ";
                            abc+=b[i]+"
    ";
                        }
    
                    }
    
                }
                textView.setText(abc);
    
                final String finalAbc = abc;
                final String finalAb = ab;
                button3.setOnClickListener(new View.OnClickListener(){
                    @Override
                    public void onClick(View view) {
                        textView.setText(finalAb);
                    }
    
    
                });
                button4.setOnClickListener(new View.OnClickListener(){
                    @Override
                    public void onClick(View view) {
                        abcd();
                    }
    
    
                });
    
    
    
    
            }
        }
    View Code
  • 相关阅读:
    00 vue源码里面常见方法
    vue 组件
    vue 样式
    vue 表单
    网络技术:NAT 网络地址转换
    网络技术:ACL 访问控制列表
    网络技术:VLAN 虚拟局域网
    Java程序设计——购物车系统
    网络 2011-2012 C 语言第三次作业批改总结
    第一用CSS
  • 原文地址:https://www.cnblogs.com/deepend/p/12274440.html
Copyright © 2020-2023  润新知