Arithmetic operators in Java
Arithmetic operators are primarily used for basic arithmetic operations, such as addition, subtraction, multiplication, division, and so on.
Arithmetic operators commonly used in Java:
650) this.width=650; "src=" http://img.mukewang.com/5368a1a10001da7603050148.jpg "/>
where+ + and -- can appear either on the left side of the operand or on the right, but the result is a different drop
650) this.width=650; "src=" http://img.mukewang.com/5368a1f1000171c403980094.jpg "/>
Operation Result: 650) this.width=650; "src=" http://img.mukewang.com/535e6a9c000128ef00900039.jpg "/>
650) this.width=650; "src=" http://img.mukewang.com/5368a0ae00016f2603970091.jpg "/>
Operation Result: 650) this.width=650; "src=" http://img.mukewang.com/535e6b040001403800890034.jpg "/>
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.
Code:
public class helloworld{
public static void Main (string[] args) {
int age1=24;
int age2=18;
int age3=36;
int age4=27;
int sum=age1+age2+age3+age4;
Double AVG=SUM/4;
int minus=age1-age2;
int newage=--age1;
System.out.println ("Sum of the Ages:" +sum);
System.out.println ("average age:" +avg);
System.out.println ("Age Difference:" +minus);
System.out.println ("Age after self-reduction:" +newage);
}
}
Operation Result:
Total Age: 105
Average age: 26.0
Age Difference: 6
Age after self-reduction: 23
This article is from "Ghost" blog, please make sure to keep this source http://caizi.blog.51cto.com/5234706/1547658
Java Basics---Java arithmetic operators (11)