码迷,mamicode.com
首页 > 其他好文 > 详细

运算符和表达式

时间:2016-03-30 19:23:42      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

1.比较运算

 技术分享

2.逻辑运算

 技术分享

3.位运算(它是与二进制打交道)

逻辑与 &

逻辑或 |

异或 ^

左位移 <<

右位移 >>

 

package com.gsa.day1;

 

/**

 * 运算符

 * 1. 算术运算: +,-,*,/,%,--,++,+=,-=,/=,%=

 * 2. 比较运算: >,<,>=,<=,!=,==

 * 3. 逻辑运算: &&,||,!,^,&,|

 * 4. 位移运算(了解): >>, <<

 * @author caleb

 *

 */

public class OperationSample {

 

public static void main(String[] args) {

int a = 1, b = 1;

System.out.println("a + b = " + (a+b));

System.out.println("a % b = " + (a%b));

 

/*

 * ++,--单目运算, 在当前变量上自加1或者自减1的操作

 * 1. ++c, 先运算然后取值

 * 2. c++, 先取值在运算

 */

int c = 1;

System.out.println("++c = " + (++c)); // c = c + 1

System.out.println("++c = " + (++c)); // c = c + 1

 

int d = 1;

System.out.println("d++ = " + (d++)); // d = d + 1

System.out.println("d = " + d);

 

int e = 1;

int f = 1;

f += e; // f = f + e;

System.out.println("f = " + f);

 

System.out.println("1 == 2  " + (1==2));

System.out.println("A > B  " + (‘A‘ > ‘B‘));

 

System.out.println("false && true  " + (false && true));

System.out.println("false || true  " + (false || true));

 

System.out.println("3 & 2  "+ (3 & 2)); //位运算的比较

System.out.println("3 | 2  " + (3 | 2)); //位运算

System.out.println("3 ^ 2  " + (3 ^ 2)); //异或

 

System.out.println("1 << 16  " + (1 << 16)); //向左移动, 转换成2进制再计算

}

}

 

4.三元运算符

语法:判断条件 1 : 2;

 

运算符和表达式

标签:

原文地址:http://www.cnblogs.com/Oueen/p/5338419.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!