Exercises for Java operator + +

Source: Internet
Author: User

First exercise:

 Public classdemo1{ Public Static voidMain (String []args) {intA = 10; intb = 10; intc = 10; A= b++;//a = 10,b = Onec =--a;//A = 9, c = 9b = ++a;//a = 10,b = TenA = c--;//A = 9, c = 8System.out.println ("a=" +a+ ", b=" +b+ ", c=" +c); }}

A second exercise:

 Public class demo1{    publicstaticvoid  main (String []args) {    int x = 4;           // 4     6         int y = (x + +) + (++x) + (x*10);    System.out.println ("x=" +x+ ", y=" +y);    // Output x = 6                     }}

A third exercise:

 Public class demo1{    publicstaticvoid  main (String []args) {    byte b = ten;    b+ +;         // B = (byte) (b+1)    b = b + 1;   // will error     // when a byte is mixed with int, The     int type will be promoted, the    result of the addition of two int is an int, and the    value assigned to byte will lose precision                }}

Exercises for Java operator + +

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.