Source: http://www.imooc.com/code/1279
Arithmetic operators are primarily used for basic arithmetic operations, such as addition, subtraction, multiplication, division, and so on.
Arithmetic operators commonly used in Java:
where+ + and -- can appear either on the left side of the operand or on the right, but the result is a different drop
Operation Result:
Operation Result:
Must pay attention to Oh! The increment and decrement operators can only be used for operation variables and cannot be used directly to manipulate values or constants! For example, 5++, 8--and so on are all wrong!
ps:% is used to find the remainder, also known as the modulo operator.
Task
Pro, use of arithmetic operators have you learned it? Let's check it out.
Please enter the code implementation function in the specified line of the editor
Line 7th: Find the sum of four ages
Line 8th: Averaging of four ages
Line 9th: Finding the difference between Age1 and Age2
Line 10th: The age after which the age1 is obtained
Operation Result:
1 Public classhelloworld{2 Public Static voidMain (string[] args) {3 intAge1=24;4 intAge2=18;5 intage3=36;6 intAge4=27;7 8 9 Ten OneSYSTEM.OUT.PRINTLN ("Total Age:" +sum); ASystem.out.println ("average age:" +avg); -System.out.println ("Age difference:" +minus); -System.out.println ("Age after Self reduction:" +newage); the - } -}
1 Public classhelloworld{2 Public Static voidMain (string[] args) {3 intAge1=24;4 intAge2=18;5 intage3=36;6 intAge4=27;7 intsum=age1+age2+age3+Age4;8 intAvg=sum/4;9 intMinus=age1-Age2;Ten intnewage=--Age1; OneSYSTEM.OUT.PRINTLN ("Total Age:" +sum); ASystem.out.println ("average age:" +avg); -System.out.println ("Age difference:" +minus); -System.out.println ("Age after Self reduction:" +newage); the - } -}
Web-android Engineer first form arithmetic operators in -3-2 Java