用Java 编写,在命令行中输入数字字符串,将其转化为整数。。这串代码怎么打,谢谢。

来源:百度知道 编辑:UC知道 时间:2024/07/05 05:28:06
楼下的。。那是转化的吧,那输入数字字符串的代码呢··
三楼的,,还是数组越界吖

import java.io.DataInputStream;

public class test {
public static void main(String[] args) {
System.out.print("请输入数字字符串:");
DataInputStream input=new DataInputStream(System.in);
try {
String str=input.readLine();
int number=Integer.parseInt(str);
System.out.println("转化为整型后:"+number);
} catch (Exception e) {
System.out.println("数据不正确或溢出");
}
}
}

取值范围:
byte -128~127
short -32768~32767
int -2^31~2^31-1
long -2^63~2^63-1
float 忘了
double忘了

puublic static void main(String[] args){
int a=Integer.parseInt(args[0]);
........
}

public static void main(String[] args) throws Exception {
System.out.println(Integer.parseInt(args[0]));
}