The four principles of computing in elementary school
Import java. util. Random;
Import java. util. collections;
Public class test {
Public static void main (String [] args ){
Int n;
Running in = new Processing (System. in );
Do {
Do {
System. out. println ("how many digits do you want to perform the four arithmetic operations? ");
N = in. nextInt ();
} While (n <1 );
Int x = new Random (). nextInt (int) Math. pow (10, n) + 1;
Int y = new Random (). nextInt (int) Math. pow (10, n) + 1;
Int o = new Random (). nextInt (3 );
Float z = 0;
Float input;
String c = "? ";
Boolean bigger = x> y? True: false; // primary school students do not receive negative numbers.
Switch (o ){
Case 0:
C = "+ ";
Z = x + y;
Break;
Case 1:
C = "-";
If (bigger)
Z = x-y;
Else
Z = y-x;
Break;
Case 2:
C = "*";
Z = x * y;
Break;
Case 3:
C = "/";
Z = (float) x/y;
Break;
Default:
System. out. println ("error! ");
}
Do {
If (bigger)
System. out. print (x + c + y + "= ");
Else
System. out. print (y + c + x + "= ");
Input = in. nextFloat ();
If (input! = Z)
System. out. println ("error! ");
} While (input! = Z );
} While (true );
}
}