Web-android Engineer first form arithmetic operators in -3-2 Java

Source: Internet
Author: User

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

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.