标签:最大 AC 先后 string ++ 示例 异或 而且 位运算符
package com.xuweiwei; /** * 运算符 */ public class Operator { public static void main(String[] args) { //定义变量 int x = 3; int y = 4; System.out.println(x+y); System.out.println(x-y); System.out.println(x*y); System.out.println(x/y);//整数相除只能得到整数 System.out.println(x%y);//取余 /** * 如果我想要整数相除不是得到整数,只需要把操作数其中一个操作数变为浮点数即可 */ System.out.println(x*1.0/y); } }
package com.xuweiwei; /** * ++、--运算符的应用 */ public class Operator2 { public static void main(String[] args) { //定义两个变量 int x = 3; int y = 4; System.out.println("x:"+x); System.out.println("y:"+y); //单独使用 x++; //相当于x=x+1; y++; System.out.println("x:"+x); System.out.println("y:"+y); x =3; y=4; //参与运算 int a = x++; //++在后面,先赋值,再自增 int b = ++y; //++在前面,先自增,再赋值 System.out.println("x:"+x); System.out.println("y:"+y); System.out.println("a:"+a); System.out.println("b:"+b); } }
package com.xuweiwei; /** * 赋值运算符 */ public class Operator3 { public static void main(String[] args) { int x = 10; System.out.println("x:" + x); int y = 10; y += 20; //相当于y = y + 20; System.out.println("y:" + y); } }
package com.xuweiwei; /** * 关系运算符 */ public class Operator4 { public static void main(String[] args) { int a = 3; int b = 4; 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 com.xuweiwei; /** * 逻辑运算符 * 特点: * 逻辑运算符一般用于连接boollean类型的表达式或值 */ public class Operator5 { public static void main(String[] args) { int a = 3; int b = 4; int c = 5; //&:一假全假 System.out.println((a > b) & (a > c)); //false & false = false System.out.println((a > b) & (a < c)); //false & true = false System.out.println((a < b) & (a > c)); //true & false = false System.out.println((a < b) & (a < c)); //true & true = true //|:一真全真 System.out.println((a > b) | (a > c)); //false & false = false System.out.println((a > b) | (a < c)); //false & true = true System.out.println((a < b) | (a > c)); //true & false = true System.out.println((a < b) | (a < c)); //true & true = true //^:相同为false,不同为true System.out.println((a > b) ^ (a > c)); //false ^ false = false System.out.println((a > b) ^ (a < c)); //false ^ true = true System.out.println((a < b) ^ (a > c)); //true ^ false = true System.out.println((a < b) ^ (a < c)); //true ^ true = false } }
package com.xuweiwei; /** * 位运算符: */ public class Operator6 { public static void main(String[] args) { int a = 3; int b = 4; System.out.println(a & b); System.out.println(a | b); System.out.println(a ^ b); System.out.println(~a); } }
package com.xuweiwei; /** * ^ * 一个数据对另一个数据异或两次,该数本身不变 */ public class Operator7 { public static void main(String[] args) { int a = 3; int b = 4; System.out.println(a ^ b ^ b); System.out.println(a ^ b ^ a); } }
package com.xuweiwei; /** * << :左边最高为丢弃,右边补0 * >> :最高位为0的时候,左边补齐0;最高位为1的时候,左边补齐1 * >>> :无论最高位是0还是1,左边补齐0 */ public class Operator8 { public static void main(String[] args) { System.out.println(3 << 2); System.out.println(24 >> 2); System.out.println(-24 >>> 2); } }
package com.xuweiwei; /** * 使用三目运算符求两个数的最大值 */ public class Operator9 { public static void main(String[] args) { int a = 10; int b = 20; System.out.println(a >= b ? a : b); } }
package com.xuweiwei; /** * 顺序结构 */ public class orderDemo { public static void main(String[] args) { System.out.println("程序开始了"); System.out.println("I love java"); System.out.println("程序结束了"); } }
if(关系表达式){ 语句体; }
package com.xuweiwei; public class IfDemo1 { public static void main(String[] args) { int x = 10; if (x >= 10) { System.out.println("x>=10"); } System.out.println("程序执行结束了"); } }
5.2
标签:最大 AC 先后 string ++ 示例 异或 而且 位运算符
原文地址:https://www.cnblogs.com/xuweiweiwoaini/p/9153695.html