
package test01; public class Demmo01 { public static void main(String[] args) { // 赋值计算将运算符和赋值符结合在一起的写法 /* 赋值运算符 a3 加法赋值 a a 5 a 5 - 减法赋值 a a - 5 a - 5 * 乘法赋值 a a * 5 a * 5 / 除法赋值 a a / 5 a / 5 % 求模赋值 a a % 5 a % 5 */ //赋值运算 int a 10; a 5; System.out.println(a); a - 5; System.out.println(a); a * 5; System.out.println(a); a / 5; System.out.println(a); a % 3; System.out.println(a); //变量值交换 a 10; int b 20; int c a; a b; b c; System.out.println(a); System.out.println(b); } }package test01; public class Demmo02 { public static void main(String[] args) { /* 位运算符将位转为二进制后按位运算 / | 按位取余两个位都是1结果就为1有0则为0 | 按位取或两个位都是0结果就为0有1则为1 ^ 按位取异或位相同为0不同为1 ~ 位取反0变11变0 右位移把a的二进制1往右移b位 左位移把a的二进制1往左移b位 */ int a 100; int b 15; System.out.println(a b); System.out.println(a | b); System.out.println(a ^ b); System.out.println(~a);// 1001 1011 -101 //1001 1011源码 //1110 0100反码 //1110 0101补码 // 计算机数值计算 原码 反码 补码 // 源码二进制本来是多少 源码就是多少 // 反码源码除符号位取反 // 补码反码1 // 计算机数值最终取的是 补码 // 正数源码 反码 补码相同 // 负数取源码的补码 System.out.println(10 3);// 0000 1010 3 0101 0000 80 //10 3 10 * 2^3 System.out.println(20 2);//5 // 20 / 2^2 System.out.println(~200); // 128648 0 1100 1000 // 源码 1 0011 0111 // 反码 1 1100 1000 // 补码 1 1100 1001 1286481 -201 } }package test01; public class Demmo03 { public static void main(String[] args) { // 三元运算符三个值参与运算的表达式 // 变量 布尔表达式 值1 值2 // a 10 , b 20 判断 a 和 b的最大值 int a 10 , b 20 , max; max a b? a : b; System.out.println(最大值是 max); int c 30; max max c? max : c; System.out.println(a,b,c中最大值是max); max (a b? a : b) c? (a b? a : b) : c; System.out.println(a,b,c中最大值是max); } }package test02; import java.util.Scanner; public class Demmo01 { public static void main(String[] args) { /* 接受用户输入可以通过输入内容完成用户和程序之间的交互 三步 1.导包需要使用的类在其他包中需要先导入 import java.util.scanner; 2.创建类的变量 类名 变量名 new 类名 Scanner sc new Scanner(System.in); 3.通过变量调用类中的方法完成输入 */ Scanner sc new Scanner(System.in); int num sc.nextInt(); System.out.println(输出的数是 num); } }package test02; import java.util.Scanner; public class Demmo02 { public static void main(String[] args) { Scanner sc new Scanner(System.in); System.out.println(请输入数值a:); int a sc.nextInt(); System.out.println(请输入数值b:); int b sc.nextInt(); System.out.println(请输入数值c:); int c sc.nextInt(); int max (a b? a : b) c? (a b? a : b) : c; System.out.println(a,b,c中最大的数值是 max); //通过Scanner,输入一个小鼠一个字符串一个整数 System.out.println(请输入一个小数); float d sc.nextFloat(); System.out.println(d); System.out.println(请输入一个字符串); String e sc.next(); System.out.println(e); System.out.println(请输入一个整数); int f sc.nextInt(); System.out.println(f); } }分支循环语句分支ifswich循环package test03; import java.util.Scanner; /* if语句如果条件成立执行代码 条件是一个布尔结果的表达式 语法1if(布尔表达式){ 代码体 } 语法2条件如果成立则执行代码体1不成立则执行2 if(条件){ 代码体1 }sles if{ 代码体2 } */ public class Demmo01 { public static void main(String[] args) { //让用户输入考试分数 》90分 奖500 Scanner sc new Scanner(System.in); System.out.println(请输入考试分数); int score sc.nextInt(); /*if(score 90){ System.out.println(考得很好奖500); }else { System.out.println(没奖); } System.out.println(); String username sc.next(); System.out.println(); String password sc.next(); */ if (score 90) { System.out.println(奖励500); } else if (score 80) { System.out.println(奖励200); } else if (score 70) { System.out.println(奖励100); } else { System.out.println(没有奖励); } } }