学习途径来源:【狂神说Java】Java零基础学习视频通俗易懂_哔哩哔哩_bilibili
public class Demo02 {
public static void main(String[] args) {
long a = 1234567L;
int b = 123;
long c = 12; //重要:如果两个操作数中有一个是long那么就会结果是long
byte d = 1; //重要:如果两个操作数中有一个是float那么就会结果是float
System.out.println(a+b+c+d); //而如果两个数其中都为其他(byte\short\int)结果都是int类型
System.out.println(b+c+d);
System.out.println(c+d);
}
}
=============================
package operater;
public class Demo03 {
public static void main(String[] args) {
double pow = Math.pow(3, 2);
System.out.println(pow);
int a = 2;
int b = ++a;
int c = a++;
System.out.println(a);
System.out.println(a);
System.out.println(b);
System.out.println(b);
System.out.println(c);
System.out.println(c);
}
}
运算结果如下:
================
public class Demo04 {
public static void main(String[] args) {
//与(and)或(or)非(取反) 与:&& 或: || 非:!()
boolean a = true;
boolean b= false;
System.out.println("a&&b:"+(a&&b));
System.out.println("a||b:"+(a||b));
System.out.println("!(a&&b):"+!(a&&b));
//短路运算
int c = 5;
boolean d = (c<4)&&(c++<4);
System.out.println(d);
System.out.println(c);
}
}
=============================
public class Demo05 {
public static void main(String[] args) {
//位运算 单独的一个&、|、^、~B 就是位运算
/*
A = 0011 1100
B = 0000 1101
A&B = 0000 1100 运算规则是: AB上下都为1结果才是1 A 与 B;
A^B = 0011 0001 运算规则是: AB上下单独有1就是1,共同为1就为0;
~B = 1111 0011 运算规则是:AB上下共同有一样的就是0
*/
/*面试题:
2*8=16 怎么运算最快 2*2*2*2
效率极高
<<左移 >> 右移
0000 0000 0
0000 0001 1
0000 0010 2 这里左移3位
0000 0011 3
0000 0100 4
0000 1000 8
0001 0000 16
*/
System.out.println(2<<3);
}
}
==================================
int a = 10 ;
int b = 20;
//面试题来咯 问说出结果有什么不同?
//字符串连接符 + String
System.out.println(""+a+b);
System.out.println(a+b+"");
==============================
public class Demo07 {
public static void main(String[] args) {
//三元运算符 优先级用()表示
/*
* X ? Y : Z 如果X = true ,结果为 Y ,否则结果为Z;
*/
int score = 50;
String type = score <60?"不及格":"及格";
System.out.println(type);
}