KhA*_*aAb 25
使用包装类.
示例如下
INT
int a = Integer.parseInt("1"); // Outputs 1
Run Code Online (Sandbox Code Playgroud)
浮动
float a = Float.parseFloat("1"); // Outputs 1.0
Run Code Online (Sandbox Code Playgroud)
双
double a = Double.parseDouble("1"); // Outputs 1.0
Run Code Online (Sandbox Code Playgroud)
长
long a = Long.parseLong("1"); // Outputs 1
Run Code Online (Sandbox Code Playgroud)
int one = Integer.parseInt("1");
Run Code Online (Sandbox Code Playgroud)
理想情况下,您也应该捕获错误:
int i;
String s = "might not be a number";
try {
i = Integer.parseInt(s);
} catch (NumberFormatException e) {
//do something
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2658 次 |
| 最近记录: |