小学数学测试题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]+"\n"; abc+=b[i]+"\n"; } } } 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]+"\n"; abc+=b[i]+"\n"; } } } 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(); } }); } }