Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
23 lines (21 loc) · 747 Bytes

File metadata and controls

23 lines (21 loc) · 747 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class TestConvert {
public static void main(String arg[]) {
int i1 = 123;
int i2 = 456;
double d1 = (i1+i2)*1.2;//系统将转换为double型运算
float f1 = (float)((i1+i2)*1.2);//需要加强制转换符
byte b1 = 67;
byte b2 = 89;
byte b3 = (byte)(b1+b2);//系统将转换为int型运算,需
//要强制转换符
System.out.println(b3);
double d2 = 1e200;
float f2 = (float)d2;//会产生溢出
System.out.println(f2);
float f3 = 1.23f;//必须加f
long l1 = 123;
long l2 = 30000000000L;//必须加l
float f = l1+l2+f3;//系统将转换为float型计算
long l = (long)f;//强制转换会舍去小数部分(不是四舍五入)
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.