服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - Java教程 - java笔记学习之操作符

java笔记学习之操作符

2021-04-24 11:55followWinter Java教程

本篇文章给大家分享了关于Java中操作符的相关知识点以及难点总结,有需要的朋友参考学习下吧。

0x001 算数运算符

java" id="highlighter_398820">
?
1
2
3
4
5
6
int num1 = 1, num2 = 2;
system.out.println(num1 + num2); // 3
system.out.println(num1 - num2); // -1
system.out.println(num1 / num2); // 0
system.out.println(num1 * num2); // 2
system.out.println(num1 % num2); //1

0x002 自增自减

?
1
2
3
4
5
6
system.out.println(num1++); // 1
system.out.println(num1); // 2
system.out.println(num1--); // 2
system.out.println(num1); // 1
system.out.println(++num1); // 2
system.out.println(--num1); // 1

0x003 关系操作符

?
1
2
3
4
system.out.println((num1 < num2)); // true
system.out.println((num1 > num2)); // false
system.out.println(num1 == num2); // false
system.out.println(num1 != num2); // true

0x004 逻辑操作符

?
1
2
3
4
5
boolean boolean1 = false;
boolean boolean2 = true;
system.out.println(boolean1 && boolean2); // false
system.out.println(boolean1 || boolean2); // true
system.out.println(!boolean1); // true

0x005 直接操作符

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
int i1 = 0x2f;
int i2 = 0x2f;
int i3 = 0177;
char c1 = 0xffff;
byte b1 = 0x7f;
short s1 = 0x7f;
long l1 = 100l;
long l2 = 100l;
float f1 = 1;
float f2 = 1f;
float f3 = 1f;
double d1 = 1d;
double d2 = 1d;
system.out.println(i1); // 47
system.out.println(i2); //47
system.out.println(i3); // 127
system.out.println(c1); //
system.out.println(b1); // 127
system.out.println(s1); // 127
system.out.println(l1); // 100
system.out.println(l2); // 100
system.out.println(f1); // 1.0
system.out.println(f2); // 1.0
system.out.println(f3); // 1.0
system.out.println(d1); // 1.0
system.out.println(d2); // 1.0

0x006 三元运算符

?
1
2
3
4
int a = 0;
boolean issuccess = false;
a = issuccess ? 1 : 2;
system.out.println(a);// 2

0x007 字符串+、+=

?
1
2
3
4
string str = "";
str = str + "1";
str += "2";
system.out.println(str);

0x008 类型转化

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int i = 100;
long long1 = (long) i;
system.out.println(long1);// 100
long1 = i;
system.out.println(long1);// 100
long long2 = (long) 200;
system.out.println(long2);// 200
i = (int) long1;
system.out.println(i); // 200
 
float float1=0.1f;
float float2=0.9f;
system.out.println((int) float1);// 转化int会被舍去
system.out.println((int) float2);// 转化int会被舍去

延伸 · 阅读

精彩推荐