public static void main(String[] args) {
String str1 = "-31";
int num1 = Integer.parseInt(str1);
System.out.print("字符串-31转换为数字:");
System.out.println(num1);
}
运行结果:
字符串-31转换为数字:-31
可以识别+ - 号
public static void main(String[] args) {
String str1 = "-31";
int num1 = Integer.parseInt(str1);
System.out.print("字符串-31转换为数字:");
System.out.println(num1);
}
运行结果:
字符串-31转换为数字:-31
可以识别+ - 号