牛耳教育十六年专注长沙java培训,是湖南最专业的长沙java培训学校。也是中国十大品牌IT教育机构,16年来总共培养了28000名软件工程师。
电话:0731-82221222

java培训系列:基本操作符运用

java培训系列:操作字符运用

前缀

postfix

++ –


i++; // i = i+1

i–; // i = i-1


unary


++expr –expr +expr -expr ~ !


加减乘除

additive,multiplicative

+ – * / %


移位

shift

<< >> >>>


条件

relational

< > <= >= instanceof


等于

equality

== !=


按位AND运算符

bitwise AND

&


按位XOR(^,异或)

bitwise exclusive OR

^


按位NOT(~,也叫作“非”运算符)属于一元运算符,生成与输入位的相反的值

~


按位OR运算符

bitwise inclusive OR

|

逻辑运算符 “与”

logical AND

&&


逻辑运算符 “或”

logical OR

||


if then else结构的缩写

ternary(shorthand for if-then-else statement)

? :


赋值运算

assignment

= += -= *= /= %= &= ^= |= <<= >>= >>>=



/**

java-er.com

learn java is so easy

*/

 

public class Operators

{

public static void main(String[] args){

int i = 10;

System.out.println("+ - ");

System.out.println("---------------------------------------");

//++ --

i++;

System.out.println("i++ "+i);

 

i--;

System.out.println("i-- " + i);

 

++i;

System.out.println("++i " + i);

 

--i;

System.out.println("--i " + i);

 

//+ - * / %

System.out.println("---------------------------------------");

System.out.println("additive,multiplicative ");

System.out.println("---------------------------------------");

int a = 5,b = 2,c;

c = a+b;

System.out.println(c);

c = a-b;

System.out.println(c);

c = a*b;

System.out.println(c);

c = a/b;

System.out.println(c);

c = a%b;

System.out.println(c);

 

 

 

//shiftAs a beginner, you will rarely use this

System.out.println("---------------------------------------");

System.out.println("shift ");

System.out.println("---------------------------------------");

c = a<<b;

System.out.println(c);

 

c = a>>b;

System.out.println(c);

 

c = a>>>b;

System.out.println(c);

 

//relational

System.out.println("---------------------------------------");

System.out.println("relational ");

System.out.println("---------------------------------------");

System.out.println(a>b);

System.out.println(a<b);

System.out.println(a>=b);

System.out.println(a<=b);

 

//equality

System.out.println("---------------------------------------");

System.out.println("equality ");

System.out.println("---------------------------------------");

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

System.out.println(a!=b);

 

//bitwise

System.out.println("---------------------------------------");

System.out.println("bitwise ");

System.out.println("---------------------------------------");

System.out.println(a&b);

System.out.println(a^b);

System.out.println(a|b);

 

//logical

int d = 4,e=8;

System.out.println("---------------------------------------");

System.out.println("logical ");

System.out.println("---------------------------------------");

System.out.println(a > b && d > e);

System.out.println(a > b || d >e);

c = a>b?a:b;

System.out.println(c);

/*ia > b ? a: b   euqals  

if(a > b){

c = a;

}else{

c = b;

}

*/

 

//assignment

 

System.out.println("---------------------------------------");

System.out.println("assignment");

System.out.println("---------------------------------------");

c = a;

c += b; //c = c + b

System.out.println(c);

c -= b; //c = c - b

System.out.println(c);

c *= b; //c = c * b

System.out.println(c);

c /= b; //c = c / b

System.out.println(c);

c %= b; //c = c % b

System.out.println(c);

c &= b; //c = c & b

System.out.println(c);

//you can test the remaining ^= |= <<= >>= >>>=

 

}

}


评论

© 牛耳教育|长沙java培训|长沙java培训学校|长沙软件培 | Powered by LOFTER