Java Basics---Java arithmetic operators (11)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.