Java Foundation-assignment operator assignment Operators with conditional operator condition Operators

Source: Internet
Author: User

Java Foundation-assignment operator assignment Operators with conditional operator condition Operators

Yun Zhengjie

Copyright Notice: Original works, declined reprint! Otherwise, the legal liability will be investigated.

I. Assignment operators

  The data type of an expression is compatible with the type of the left variable

1>: General Assignment

1 /*2 @author: Yinzhengjie3 Blog:http://www.cnblogs.com/yinzhengjie/tag/Java%E5%9F%BA%E7%A1%80/4 Email:[email protected]5 */6 7  Public classassignment{8      Public Static voidMain (string[] args) {9         //1> Assign a valueTen         intx = 123; One          Ax = 123 + 5; -          -         inty = X/2; the          -         //int z = 3.1415926;//type is incompatible.  -          -SYSTEM.OUT.PRINTLN (x);// - +System.out.println (y);// - -     } +}

2>: Conforming to assignment, reflexive assignment

1 /*2 @author: Yinzhengjie3 Blog:http://www.cnblogs.com/yinzhengjie/tag/Java%E5%9F%BA%E7%A1%80/4 Email:[email protected]5 */6 7  Public classassignment2{8      Public Static voidMain (string[] args) {9         //compound assignment implies strongly typed conversionsTen          One         byteA = 10; A          -A + = 5;//equivalent to A = (byte) (A + 5) -          theSystem.out.println (a);// the - } -}

Two. Conditional operators

The conditional operator is also called the ternary operator. Syntax format: "(condition)?" Expression 1: Expression 2 ", if the condition is true, the value of the entire expression is the value of expression 1, and if the condition is not true, the value of the entire expression is the value of expression 2.

Java Foundation-assignment operator assignment Operators with conditional operator condition Operators

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.