package com;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Test4_36Arithmetics {
//定义两个变量表示背景图的宽高
static int bgWidth=1000;
static int bgHeight=900;
//主函数: 让作用是程序能运行
public static void main(String[] args) {
JFrame win =new JFrame();
Content4 jp=new Content4();
jp.setLayout(null);
win.add(jp);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setSize(bgWidth,bgHeight);
win.setVisible( true );//用win变量调用setVisiable()函数让窗口显示
// win.setLocationRelativeTo(null);//让win代表的窗口居中
}
}
/**自定义一个类Content4继承JPanel充当面板类*/
class Content4 extends JPanel{
public void paint(Graphics g) {
g.setColor(Color.white);
g.fillRect(0, 0, Test2.bgWidth, Test2.bgHeight);
paintTwoNum_arithmetics(g);
paintThreeNum_arithmetics(g);
paintThourNum_arithmetics(g);
}
int i=1;
int twoNumArithmetics_count=10;
/**1.绘制两个数字的加减法*/
private void paintTwoNum_arithmetics(Graphics g) {
i=1;//为了避免java swing界面技术的bug,将i两次赋值为1
Font f=new Font("黑体",Font.BOLD,25);
g.setFont(f);
g.setColor(Color.BLACK);
//1.生成两个数字的加减法
List<String> list=generate_twoNum_Arithmetics();
int x=20;
g.setColor(Color.BLACK);
for(;i<=twoNumArithmetics_count;i++){
g.drawString(list.get(i-1), x, 35*i);
}
}
int threeNum_arithmetics=10;
/**2.绘制三个数字的加减法*/
private void paintThreeNum_arithmetics(Graphics g) {
i=twoNumArithmetics_count+1;//为了避免java swing界面技术的bug,将i手动赋值为11
Font f=new Font("黑体",Font.BOLD,25);
g.setFont(f);
g.setColor(Color.BLACK);
int x=20;
//2.生成三个数字的加减法
List<String> list2=generate_ThreeNum_Arithmetics();
for(int j=0;j<10;j++){
g.drawString(list2.get(j), x, 35*i);
i++;
if(i>=19){
i=1;
x=300;
}
System.out.println("for::"+i);
}
System.out.println(i);
}
/**3.绘制四个数字的加减法*/
private void paintThourNum_arithmetics(Graphics g) {
i=(threeNum_arithmetics+twoNumArithmetics_count)%18+1;
int x=20;
if(threeNum_arithmetics+twoNumArithmetics_count>18){
x=(threeNum_arithmetics+twoNumArithmetics_count)/18 *300;
}
//3.生成四个数字的加减法
List<String> list3=genetateThourNum_arithmetics();
for(int j=0;j<16;j++){
if(i>=19){
i=1;
x=300;
}
g.drawString(list3.get(j), x, 35*i);
// System.out.println(40*i +",aaa,"+list2.get(j));
i++;
}
}
/**为了对齐显示, 将小于10的数前边补0*/
private String[] number_addZero(int[] numbers){
String[] str_numbers=new String[numbers.length];
for(int i=0;i<numbers.length; i++){
if(numbers[i]<10){
str_numbers[i]="0"+numbers[i];
}else{
str_numbers[i]=""+numbers[i];
}
}
return str_numbers;
}
/**生成一个两个数字的加减法算式(结果是20以内的进位借位的两个数字的加减法),例如 8+9=*/
List<String> generate_twoNum_Arithmetics(){
String[] tOperator={"+", "-"};
ArrayList<String> list=new ArrayList<String>();
String aOperator="";
String arithmetic="";
for(int i=1;i<=40;i++){
int num1=(int)(Math.random()*20)+4;
int num2=(int)(Math.random()*11)+3;
aOperator=tOperator[i%2];
int ge1=num1%10;
int ge2=num2%10;
int[] nums={num1,num2};
String[] str_numbers=number_addZero(nums);
if((aOperator).equals("+")){
arithmetic=str_numbers[0]+"+"+str_numbers[1]+"=";
while( 9>(num1+num2) || (num1+num2)>20 || list.contains(arithmetic) || (ge1+ge2)<=10 ){
num1=(int)(Math.random()*20)+4;
num2=(int)(Math.random()*11)+3;
ge1=num1%10;
ge2=num2%10;
nums=new int[]{num1,num2};
str_numbers=number_addZero(nums);
arithmetic= str_numbers[0]+"+"+str_numbers[1]+"=" ;
}
}else if((aOperator).equals("-")){
arithmetic=str_numbers[0]+"-"+str_numbers[1]+"=";
while( num1<num2 || (num1-num2)<8 || (num1-num2)>11 || ge1>=ge2 || list.contains(arithmetic)){
num1=(int)(Math.random()*20)+4;
num2=(int)(Math.random()*11)+3;
ge1=num1%10;
ge2=num2%10;
nums=new int[]{num1,num2};
str_numbers=number_addZero(nums);
arithmetic= str_numbers[0]+"-"+str_numbers[1]+"=";
}
}
list.add(arithmetic);
}
return list;
}
/**生成三个数字的加减法,例如4+8+2=*/
List<String> generate_ThreeNum_Arithmetics(){
String[] tOpe={"+", "-"};
ArrayList<String> list=new ArrayList<String>();
String aOpe="",bOpe="";
String arithmetic="";
for(int i=1;i<=10;i++){
int num1=(int)(Math.random()*13)+1;
int num2=(int)(Math.random()*10)+1;
int num3=(int)(Math.random()*10)+5;
int index=(int)(Math.random()*2);
aOpe=tOpe[index];
index=(int)(Math.random()*2);
bOpe=tOpe[index];
int[] nums={num1,num2,num3};
String[] str_numbers=number_addZero(nums);
int ge1=num1%10;
int ge2=num2%10;
if((aOpe).equals("+")){
arithmetic=str_numbers[0]+"+"+str_numbers[1]+bOpe+str_numbers[2]+"=";
int rs=100;
if(bOpe.equals("-")){
rs=num1+num2-num3;
}else{
rs=num1+num2+num3;
}
while( 9>(num1+num2) || (num1+num2)>16 || list.contains(arithmetic) || (ge1+ge2)<=8 || rs<=0 ){
num1=(int)(Math.random()*20)+4;
num2=(int)(Math.random()*11)+3;
num3=(int)(Math.random()*11)+3;
ge1=num1%10;
ge2=num2%10;
if(bOpe.equals("-")){
rs=num1+num2-num3;
}else{
rs=num1+num2+num3;
}
nums=new int[]{num1,num2,num3};
str_numbers=number_addZero(nums);
arithmetic=str_numbers[0]+"+"+str_numbers[1]+bOpe+str_numbers[2]+"=";
}
}else if((aOpe).equals("-")){
int rs=num1-num2;
arithmetic=str_numbers[0]+"-"+str_numbers[1]+bOpe+str_numbers[2]+"=";
if("-".equals(bOpe)){
rs=num1-num2-num3;
}else{
rs=num1-num2+num3;
}
while( num1<num2 || rs<8 || rs>11 || ge1>ge2 || list.contains(arithmetic) ||rs<=0){
num1=(int)(Math.random()*20)+4;
num2=(int)(Math.random()*11)+3;
num3=(int)(Math.random()*10)+5;
rs=num1-num2;
ge1=num1%10;
ge2=num2%10;
if("-".equals(bOpe)){
rs=num1-num2-num3;
}else{
rs=num1-num2+num3;
}
nums=new int[]{num1,num2,num3};
str_numbers=number_addZero(nums);
arithmetic=str_numbers[0]+"+"+str_numbers[1]+bOpe+str_numbers[2]+"=";
}
}
list.add(arithmetic);
}
return list;
}
/**生成四个数字的加减法: 生成一个已知算式 且结果等于另一个算式(此算式某个数是未知数), 例如 4+5=6+( )*/
private List<String> genetateThourNum_arithmetics() {
String[] tOpe={"=", "o"};
ArrayList<String> list=new ArrayList<String>();
String aOpe="";
String arithmetic="";
for(int i=1;i<=100;i++){
int num1=(int)(Math.random()*20)+4;
int num2=(int)(Math.random()*11)+3;
String number1="",number2="", number3="";
aOpe=tOpe[i%2];
int ge1=num1%10;
int ge2=num2%10;
int ranNum=(int)(Math.random()*4+1);
if((aOpe).equals("=")){
arithmetic=generate_twoNum_oneArithmetic();
String[] numbers=arithmetic.split("[+-]");
String[] numbers2=numbers[1].split("=");
int n1=Integer.parseInt(numbers[0]);
int n2=Integer.parseInt(numbers2[0]);
ranNum=1;
if(ranNum==1){
int n3=n1+n2-(int)((Math.random()*(n1+n2-1))+1);
while(n3==n1 || n3==n2){
n3=n1+n2-(int)((Math.random()*(n1+n2-1))+1);
}
int[] nums=new int[]{n1, n2, n3};
String[] str_numbers=number_addZero(nums);
list.add(str_numbers[0]+"+"+str_numbers[1]+"="+str_numbers[2]+"+( )");
}else if(ranNum==2){
int n3=n1+n2-(int)((Math.random()*12)+1);
while(n3==n1 || n3==n2 || n3==0){
n3=n1+n2-(int)((Math.random()*(n1+n2))+1);
}
int[] nums=new int[]{n1, n2, n3};
String[] str_numbers=number_addZero(nums);
list.add(str_numbers[0]+"+"+str_numbers[1]+"="+str_numbers[2]+"-( )");
System.out.println(n1+"+"+n2+"="+n3+"-( )");
}else if(ranNum==3){
int rs=num1-num2;
arithmetic=number1+"-"+number2+"=";
while( num1<num2 || rs<8 || rs>11 || ge1>ge2 || list.contains(arithmetic)){
num1=(int)(Math.random()*20)+4;
num2=(int)(Math.random()*11)+3;
rs=num1-num2;
ge1=num1%10;
ge2=num2%10;
}
int num3=num1-num2-(int)((Math.random()*(num1-num2))+1);
while(num3==0 || num3==num1 || num3==num2){
num3=num1-num2-(int)((Math.random()*(num1-num2))+1);
}
int[] nums=new int[]{num1, num2, num3};
String[] str_numbers=number_addZero(nums);
list.add(str_numbers[0]+"-"+str_numbers[1]+"="+str_numbers[2]+"+( )");
System.out.println(number1+"-"+number2+"="+number3+"+ ( )");
}else if(ranNum==4){
int rs=num1-num2;
while( num1<num2 || rs<8 || rs>11 || ge1>ge2 || list.contains(arithmetic)){
num1=(int)(Math.random()*20)+4;
num2=(int)(Math.random()*11)+3;
rs=num1-num2;
ge1=num1%10;
ge2=num2%10;
}
int num4=(int)((Math.random()*(num1-num2))+1);
int num3=num1-num2+num4;
int[] nums=new int[]{num1, num2, num3};
String[] str_numbers=number_addZero(nums);
list.add(str_numbers[0]+"-"+str_numbers[1]+"="+str_numbers[2]+"+( )");
System.out.println(number1+"-"+number2+"="+number3+"- ( )");
}
}else if((aOpe).equals("o")){
String a_arithmetic=generate_twoNum_oneArithmetic();
String[] arithmetic_equals1=a_arithmetic.split("=");
String b_arithmetic=generate_twoNum_oneArithmetic();
String[] arithmetic_equals2=b_arithmetic.split("=");
list.add(arithmetic_equals1[0]+"〇"+arithmetic_equals2[0]);
}
}
return list;
}
/**用于生成两道加减法算式*/
public String generate_twoNum_oneArithmetic(){
String[] tOpe={"+", "-"};
ArrayList<String> list=new ArrayList<String>();
String aOpe="";
String arithmetic="";
int num1=(int)(Math.random()*20)+4;
int num2=(int)(Math.random()*11)+3;
int index=(int)(Math.random()*2);
aOpe=tOpe[index];
int ge1=num1%10;
int ge2=num2%10;
int[] nums=new int[]{num1, num2};
String[] str_numbers=number_addZero(nums);
if((aOpe).equals("+")){
arithmetic=str_numbers[0]+"+"+str_numbers[1]+"=";
while( 9>(num1+num2) || (num1+num2)>19 || list.contains(arithmetic) || (ge1+ge2)<=10 ){
num1=(int)(Math.random()*20)+4;
num2=(int)(Math.random()*11)+3;
ge1=num1%10;
ge2=num2%10;
nums=new int[]{num1, num2};
str_numbers=number_addZero(nums);
arithmetic=str_numbers[0]+"+"+str_numbers[1]+"=";
}
list.add(arithmetic);
}else if((aOpe).equals("-")){
int rs=num1-num2;
arithmetic=str_numbers[0]+"-"+str_numbers[1]+"=";
while( num1<num2 || rs<8 || rs>15 || ge1>ge2 || list.contains(arithmetic)){
num1=(int)(Math.random()*20)+4;
num2=(int)(Math.random()*11)+3;
rs=num1-num2;
ge1=num1%10;
ge2=num2%10;
nums=new int[]{num1, num2};
str_numbers=number_addZero(nums);
arithmetic=str_numbers[0]+"-"+str_numbers[1]+"=";
}
list.add(arithmetic);
}
return arithmetic;
}
}
package com; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.util.ArrayList; import java.util.List; import javax.swing.JFrame; import javax.swing.JPanel; public class Test4_36Arithmetics { //定义两个变量表示背景图的宽高 static int bgWidth=1000; static int bgHeight=900; //主函数: 让作用是程序能运行 public static void main(String[] args) { JFrame win =new JFrame(); Content4 jp=new Content4(); jp.setLayout(null); win.add(jp); win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); win.setSize(bgWidth,bgHeight); win.setVisible( true );//用win变量调用setVisiable()函数让窗口显示 // win.setLocationRelativeTo(null);//让win代表的窗口居中 } } /**自定义一个类Content4继承JPanel充当面板类*/ class Content4 extends JPanel{ public void paint(Graphics g) { g.setColor(Color.white); g.fillRect(0, 0, Test2.bgWidth, Test2.bgHeight); paintTwoNum_arithmetics(g); paintThreeNum_arithmetics(g); paintThourNum_arithmetics(g); } int i=1; int twoNumArithmetics_count=10; /**1.绘制两个数字的加减法*/ private void paintTwoNum_arithmetics(Graphics g) { i=1;//为了避免java swing界面技术的bug,将i两次赋值为1 Font f=new Font("黑体",Font.BOLD,25); g.setFont(f); g.setColor(Color.BLACK); //1.生成两个数字的加减法 List<String> list=generate_twoNum_Arithmetics(); int x=20; g.setColor(Color.BLACK); for(;i<=twoNumArithmetics_count;i++){ g.drawString(list.get(i-1), x, 35*i); } } int threeNum_arithmetics=10; /**2.绘制三个数字的加减法*/ private void paintThreeNum_arithmetics(Graphics g) { i=twoNumArithmetics_count+1;//为了避免java swing界面技术的bug,将i手动赋值为11 Font f=new Font("黑体",Font.BOLD,25); g.setFont(f); g.setColor(Color.BLACK); int x=20; //2.生成三个数字的加减法 List<String> list2=generate_ThreeNum_Arithmetics(); for(int j=0;j<10;j++){ g.drawString(list2.get(j), x, 35*i); i++; if(i>=19){ i=1; x=300; } System.out.println("for::"+i); } System.out.println(i); } /**3.绘制四个数字的加减法*/ private void paintThourNum_arithmetics(Graphics g) { i=(threeNum_arithmetics+twoNumArithmetics_count)%18+1; int x=20; if(threeNum_arithmetics+twoNumArithmetics_count>18){ x=(threeNum_arithmetics+twoNumArithmetics_count)/18 *300; } //3.生成四个数字的加减法 List<String> list3=genetateThourNum_arithmetics(); for(int j=0;j<16;j++){ if(i>=19){ i=1; x=300; } g.drawString(list3.get(j), x, 35*i); // System.out.println(40*i +",aaa,"+list2.get(j)); i++; } } /**为了对齐显示, 将小于10的数前边补0*/ private String[] number_addZero(int[] numbers){ String[] str_numbers=new String[numbers.length]; for(int i=0;i<numbers.length; i++){ if(numbers[i]<10){ str_numbers[i]="0"+numbers[i]; }else{ str_numbers[i]=""+numbers[i]; } } return str_numbers; } /**生成一个两个数字的加减法算式(结果是20以内的进位借位的两个数字的加减法),例如 8+9=*/ List<String> generate_twoNum_Arithmetics(){ String[] tOperator={"+", "-"}; ArrayList<String> list=new ArrayList<String>(); String aOperator=""; String arithmetic=""; for(int i=1;i<=40;i++){ int num1=(int)(Math.random()*20)+4; int num2=(int)(Math.random()*11)+3; aOperator=tOperator[i%2]; int ge1=num1%10; int ge2=num2%10; int[] nums={num1,num2}; String[] str_numbers=number_addZero(nums); if((aOperator).equals("+")){ arithmetic=str_numbers[0]+"+"+str_numbers[1]+"="; while( 9>(num1+num2) || (num1+num2)>20 || list.contains(arithmetic) || (ge1+ge2)<=10 ){ num1=(int)(Math.random()*20)+4; num2=(int)(Math.random()*11)+3; ge1=num1%10; ge2=num2%10; nums=new int[]{num1,num2}; str_numbers=number_addZero(nums); arithmetic= str_numbers[0]+"+"+str_numbers[1]+"=" ; } }else if((aOperator).equals("-")){ arithmetic=str_numbers[0]+"-"+str_numbers[1]+"="; while( num1<num2 || (num1-num2)<8 || (num1-num2)>11 || ge1>=ge2 || list.contains(arithmetic)){ num1=(int)(Math.random()*20)+4; num2=(int)(Math.random()*11)+3; ge1=num1%10; ge2=num2%10; nums=new int[]{num1,num2}; str_numbers=number_addZero(nums); arithmetic= str_numbers[0]+"-"+str_numbers[1]+"="; } } list.add(arithmetic); } return list; } /**生成三个数字的加减法,例如4+8+2=*/ List<String> generate_ThreeNum_Arithmetics(){ String[] tOpe={"+", "-"}; ArrayList<String> list=new ArrayList<String>(); String aOpe="",bOpe=""; String arithmetic=""; for(int i=1;i<=10;i++){ int num1=(int)(Math.random()*13)+1; int num2=(int)(Math.random()*10)+1; int num3=(int)(Math.random()*10)+5; int index=(int)(Math.random()*2); aOpe=tOpe[index]; index=(int)(Math.random()*2); bOpe=tOpe[index]; int[] nums={num1,num2,num3}; String[] str_numbers=number_addZero(nums); int ge1=num1%10; int ge2=num2%10; if((aOpe).equals("+")){ arithmetic=str_numbers[0]+"+"+str_numbers[1]+bOpe+str_numbers[2]+"="; int rs=100; if(bOpe.equals("-")){ rs=num1+num2-num3; }else{ rs=num1+num2+num3; } while( 9>(num1+num2) || (num1+num2)>16 || list.contains(arithmetic) || (ge1+ge2)<=8 || rs<=0 ){ num1=(int)(Math.random()*20)+4; num2=(int)(Math.random()*11)+3; num3=(int)(Math.random()*11)+3; ge1=num1%10; ge2=num2%10; if(bOpe.equals("-")){ rs=num1+num2-num3; }else{ rs=num1+num2+num3; } nums=new int[]{num1,num2,num3}; str_numbers=number_addZero(nums); arithmetic=str_numbers[0]+"+"+str_numbers[1]+bOpe+str_numbers[2]+"="; } }else if((aOpe).equals("-")){ int rs=num1-num2; arithmetic=str_numbers[0]+"-"+str_numbers[1]+bOpe+str_numbers[2]+"="; if("-".equals(bOpe)){ rs=num1-num2-num3; }else{ rs=num1-num2+num3; } while( num1<num2 || rs<8 || rs>11 || ge1>ge2 || list.contains(arithmetic) ||rs<=0){ num1=(int)(Math.random()*20)+4; num2=(int)(Math.random()*11)+3; num3=(int)(Math.random()*10)+5; rs=num1-num2; ge1=num1%10; ge2=num2%10; if("-".equals(bOpe)){ rs=num1-num2-num3; }else{ rs=num1-num2+num3; } nums=new int[]{num1,num2,num3}; str_numbers=number_addZero(nums); arithmetic=str_numbers[0]+"+"+str_numbers[1]+bOpe+str_numbers[2]+"="; } } list.add(arithmetic); } return list; } /**生成四个数字的加减法: 生成一个已知算式 且结果等于另一个算式(此算式某个数是未知数), 例如 4+5=6+( )*/ private List<String> genetateThourNum_arithmetics() { String[] tOpe={"=", "o"}; ArrayList<String> list=new ArrayList<String>(); String aOpe=""; String arithmetic=""; for(int i=1;i<=100;i++){ int num1=(int)(Math.random()*20)+4; int num2=(int)(Math.random()*11)+3; String number1="",number2="", number3=""; aOpe=tOpe[i%2]; int ge1=num1%10; int ge2=num2%10; int ranNum=(int)(Math.random()*4+1); if((aOpe).equals("=")){ arithmetic=generate_twoNum_oneArithmetic(); String[] numbers=arithmetic.split("[+-]"); String[] numbers2=numbers[1].split("="); int n1=Integer.parseInt(numbers[0]); int n2=Integer.parseInt(numbers2[0]); ranNum=1; if(ranNum==1){ int n3=n1+n2-(int)((Math.random()*(n1+n2-1))+1); while(n3==n1 || n3==n2){ n3=n1+n2-(int)((Math.random()*(n1+n2-1))+1); } int[] nums=new int[]{n1, n2, n3}; String[] str_numbers=number_addZero(nums); list.add(str_numbers[0]+"+"+str_numbers[1]+"="+str_numbers[2]+"+( )"); }else if(ranNum==2){ int n3=n1+n2-(int)((Math.random()*12)+1); while(n3==n1 || n3==n2 || n3==0){ n3=n1+n2-(int)((Math.random()*(n1+n2))+1); } int[] nums=new int[]{n1, n2, n3}; String[] str_numbers=number_addZero(nums); list.add(str_numbers[0]+"+"+str_numbers[1]+"="+str_numbers[2]+"-( )"); System.out.println(n1+"+"+n2+"="+n3+"-( )"); }else if(ranNum==3){ int rs=num1-num2; arithmetic=number1+"-"+number2+"="; while( num1<num2 || rs<8 || rs>11 || ge1>ge2 || list.contains(arithmetic)){ num1=(int)(Math.random()*20)+4; num2=(int)(Math.random()*11)+3; rs=num1-num2; ge1=num1%10; ge2=num2%10; } int num3=num1-num2-(int)((Math.random()*(num1-num2))+1); while(num3==0 || num3==num1 || num3==num2){ num3=num1-num2-(int)((Math.random()*(num1-num2))+1); } int[] nums=new int[]{num1, num2, num3}; String[] str_numbers=number_addZero(nums); list.add(str_numbers[0]+"-"+str_numbers[1]+"="+str_numbers[2]+"+( )"); System.out.println(number1+"-"+number2+"="+number3+"+ ( )"); }else if(ranNum==4){ int rs=num1-num2; while( num1<num2 || rs<8 || rs>11 || ge1>ge2 || list.contains(arithmetic)){ num1=(int)(Math.random()*20)+4; num2=(int)(Math.random()*11)+3; rs=num1-num2; ge1=num1%10; ge2=num2%10; } int num4=(int)((Math.random()*(num1-num2))+1); int num3=num1-num2+num4; int[] nums=new int[]{num1, num2, num3}; String[] str_numbers=number_addZero(nums); list.add(str_numbers[0]+"-"+str_numbers[1]+"="+str_numbers[2]+"+( )"); System.out.println(number1+"-"+number2+"="+number3+"- ( )"); } }else if((aOpe).equals("o")){ String a_arithmetic=generate_twoNum_oneArithmetic(); String[] arithmetic_equals1=a_arithmetic.split("="); String b_arithmetic=generate_twoNum_oneArithmetic(); String[] arithmetic_equals2=b_arithmetic.split("="); list.add(arithmetic_equals1[0]+"〇"+arithmetic_equals2[0]); } } return list; } /**用于生成两道加减法算式*/ public String generate_twoNum_oneArithmetic(){ String[] tOpe={"+", "-"}; ArrayList<String> list=new ArrayList<String>(); String aOpe=""; String arithmetic=""; int num1=(int)(Math.random()*20)+4; int num2=(int)(Math.random()*11)+3; int index=(int)(Math.random()*2); aOpe=tOpe[index]; int ge1=num1%10; int ge2=num2%10; int[] nums=new int[]{num1, num2}; String[] str_numbers=number_addZero(nums); if((aOpe).equals("+")){ arithmetic=str_numbers[0]+"+"+str_numbers[1]+"="; while( 9>(num1+num2) || (num1+num2)>19 || list.contains(arithmetic) || (ge1+ge2)<=10 ){ num1=(int)(Math.random()*20)+4; num2=(int)(Math.random()*11)+3; ge1=num1%10; ge2=num2%10; nums=new int[]{num1, num2}; str_numbers=number_addZero(nums); arithmetic=str_numbers[0]+"+"+str_numbers[1]+"="; } list.add(arithmetic); }else if((aOpe).equals("-")){ int rs=num1-num2; arithmetic=str_numbers[0]+"-"+str_numbers[1]+"="; while( num1<num2 || rs<8 || rs>15 || ge1>ge2 || list.contains(arithmetic)){ num1=(int)(Math.random()*20)+4; num2=(int)(Math.random()*11)+3; rs=num1-num2; ge1=num1%10; ge2=num2%10; nums=new int[]{num1, num2}; str_numbers=number_addZero(nums); arithmetic=str_numbers[0]+"-"+str_numbers[1]+"="; } list.add(arithmetic); } return arithmetic; } }
文章来源地址https://www.toymoban.com/news/detail-661664.html
文章来源:https://www.toymoban.com/news/detail-661664.html
到了这里,关于小学20以内加减法_自动生成器的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!