java operate

扫码查看
class OperateDemo
{
public static void main(String[] args)
{
/*
+ - * / %(取余数)
*/
int x = 2810;
System.out.println(x/1000);
System.out.println(2%-5);
/*
++:自增。对原有的数据进行+1
java  operate-LMLPHP
int a = 3;
a++;//++a;//a = a+1; ++运算单独存在时,放左放右是没有区别的。
System.out.println("a="+a);
*/
int a = 3, b;
//b = ++a;
b = a++;
System.out.println("a="+a+",b="+b);
System.out.println("5+5="+(5+5));
/*
赋值运算符。
= += -= *= /= %=
*/
//int x,y,z;
//x=y=z=3;
int a = 3;//右边赋给左边。
a+=4;//将左右两边的和赋给左边。 a = a + 4;
short s = 4;
//s = s + 5;//编译失败。
s+=5;//编译通过,会做自动转换。
/*
比较运算符。运算完的结果要么true,要么false。
*/
System.out.println(3!=4); /*
逻辑运算符。用来连接boolean型表达式的。
& : 与
| :或
^ : 异或。
!:非。 && 短路与 || 短路或
*/ int x = 7; //x>2 & x<5
//x<2 | x>5
/*
& :两边都为true,结果是true。否则为false。
两边只要有一个false。结果必然是false。
*/
true & true = true;
true & false = false;
false & true = false;
false & false = false; /*
| :两边都为false,结果是false。否则为true。
两边只要有一个true。结果必然是true。 */
true | true = true;
true | false = true;
false | true = true;
false | false = false; /*
^ : 异或。
两边相同为false。两边不同为true。
*/
true ^ true = false;
true ^ false = true;
false ^ true = true;
false ^ false = false; !true = false; int y = 1; y>3 & y<6
y>3 && y<6 /*
&和&&的区别:
&:两边都参与运算。
&&:当左边为false。右边不参与运算。 |和 ||
| :两边都参与运算。
|| :当左边为true,右边不参与运算。
*/
    }
}
05-07 15:07
查看更多