package study;
/**
*
*/
public class TestDemo {
public static void main(String[] args) {
System.out.println(5/2);
System.out.println(5.0/2);
System.out.println((float)5/2);
System.out.println((float)(5/2));
}
}
控制台运行结果:
package study;
/**
*
*/
public class TestDemo {
public static void main(String[] args) {
System.out.println(10%3);
System.out.println(-10%3);
System.out.println(10%-3);
System.out.println(-10%-3);
}
}
JAVA中的异常
package study;
/**
*
*/
public class TestDemo {
public static void main(String[] args) {
// System.out.println(10%3);
// System.out.println(-10%3);
// System.out.println(10%-3);
// System.out.println(-10%-3);
System.out.println(5/0);
}
}
package study;
/**
*
*/
public class TestDemo {
public static void main(String[] args) {
// System.out.println(10%3);
// System.out.println(-10%3);
// System.out.println(10%-3);
// System.out.println(-10%-3);
// System.out.println(5/0);
int a = 10;
int b = ++a; //a 先++ 后赋值
System.out.println(b);// a = 11 , b = 11
int c = a ++; //a 先赋值,后++
System.out.println(c);// c = 11 , a = 12
}
}
package study;
/**
*
*/
public class TestDemo {
public static void main(String[] args) {
int a = 10;
int b = 20;
System.out.println(a == b);
System.out.println(a != b);
System.out.println(a < b);
System.out.println(a > b);
System.out.println(a >= b);
System.out.println(a <= b);
}
package study;
/**
*
*/
public class TestDemo {
public static void main(String[] args) {
//逻辑与 &&
int a = 10;
int b = 20;
int c = 30;
// System.out.println(a < b && b < c);
//逻辑或 ||
int d = 10;
int e = 20;
int f = 30;
System.out.println(d < e || e < f);
}
表达式1 && 表达式2 必须保证两个表达式都为真,整体才是真 表达式1 || 表达式2 只有一个表达式为真,那么整体就是真
!:非,后面只能跟布尔类型的数据
package study;
/**
*
*/
public class TestDemo {
public static void main(String[] args) {
//逻辑与 &&
int a = 10;
int b = 20;
// System.out.println(!a < b);
boolean flg = true;
System.out.println(!flg);
}
}
几进制就是用几个数字表示
按位与 & :相当于乘法 按位或 | : 把它看成加法 按位异或^: 一样就是0,不一样就是1
按位取反~:把0变成1,1变成0