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