A simple addition, subtraction, multiplication, division, automatic generation of small programs (JAVA), addition, subtraction, multiplication, division, and java
When I was studying software engineering, I encountered such a problem. When a programmer's son went to the second grade of elementary school, the teacher asked the parents to give 30 questions to the students every day. Because the parents were programmers, so, he wrote a program implementation by himself. Our lovely teacher also told us to write a program similar to this, but I still have some shortcomings in this program. First: if the question does not match the meaning of the question, it should only be able to add or subtract, but I still have the multiplication and division, haha, but it can be changed a little. The second is that although the program can output the answer, because I set the result to only the INT type, the answer to division is incorrect. The third is that some multiplication numbers are relatively large, and the second-year users cannot calculate the result; also, I have not made any parentheses. Because I am a beginner in JAVA, it took quite a few hours to develop this program. Because there are some modifications. The source code is provided below:
Import java. util. collections;
Public class Sizeyunsuan {
Public static void main (String [] args ){
Running in = new Processing (System. in );
System. out. println ("the number of arithmetic operations you want to output is :");
Int num = in. nextInt ();
String [] a = {"+ ","-","*","/"};
Int [] B;
Int [] c; int j = 0;
B = new int [4]; c = new int [4];
Do {
Int sum =-1;
For (int I = 0; I <4; I ++)
{
B [I] = (int) (Math. random () * 100 );
}
For (int I = 0; I <4; I ++)
{
C [I] = (int) (Math. random () * 14/3 );
}
Switch (c [0])
{
Case 1: sum = B [0] + B [1]; break;
Case 2: sum = B [0]-B [1]; break;
Case 3: sum = B [0] * B [1]; break;
Case 4: sum = B [0]/B [1]; break;
}
If (sum <0)
{
J --;
}
Else
{
System. out. println (B [0] + a [c [0]-1] + B [1] + "= ");
// System. out. println (sum); // The result is displayed.
}
J ++;
} While (j <num );
}
}