We all know what arithmetic operators are. He is the + in mathematics-*/In addition to these, there is an arithmetic operator in Java:% take-away (take the film)% he can be called to take the surplus can also be said to take the film two names can be. So what was he used for? For example: 10%3 holding the right 3 Q: 10 can divide 3, if the result is 0, if not an integer, the result is the remainder. So the 10%3=1 result is: 1 is holding the remainder of the 10/3=3 1, the remainder of 1 to the results of the surplus. 4.2 is shown below:
650) this.width=650; "src=" Http://img.mp.itc.cn/upload/20160414/ba2b1cb5c8fc4e3eb29f081333450f84.jpg "style=" border:0px;margin:0px;padding:0px;font-size:0px; "/>
Figure 4.2
Can be variable directly receive the residual value or add value, etc. can be, for example: int i = 10%3; or int i = 10+3; This means that they take the remainder first, and then give the result of the remainder to the variable I or they first add and then give the result of the addition to the variable i. A variable can also receive the result of an operation between two variables such as int i = 10; int a = 2;
int b = I+a; The result of adding two variables I and a is given to the variable B.
What is the use of the remainder operator? Simple to say that do not understand, for example, the client is connected to the server, he is using the operation of the redundancy to connect, the previous data through the calculation of the value of the next few to be used as a verification bit, if the client sends the data that can be connected to the server.
Note: There are type descriptions when you count in Java, for example: int i = 8*3l; At the time of the operation who is the biggest result is whose, so int i = 8*3l; This operation will be an error, he came to the result is a long type, so he must be forced to cast into the int type. Let him finish the operation before going to the cast type, for example: int i = (int) (8*3L); This means that you first have the result of a long type, and then I will cast the result of your operation to the value of type long as the type of int.
Technology sharing: www.kaige123.com
This article is from the "11247808" blog, please be sure to keep this source http://11257808.blog.51cto.com/11247808/1889861
Java Arithmetic operators