trys byte buff] = new byte[255); System.out.printn("清输入:"); System.in read(buf, 0, 255); System.out.printnc您的输入如下:"; 1请补全这里的代码 } catch(IOException ioe)‹ ioe.printStackTraceO; 建议尝试用 Eclipse 的debug(调试)功能,看看你输入到buf中的是什么。不出意外,应该是 ASCI 码。如何把它转换成整型数?
时间: 2024-03-19 17:45:58 浏览: 9
要将输入的 ASCI 码转换成整型数,可以使用 Java 中的 Integer.parseInt() 方法。具体实现如下:
```
try {
byte[] buf = new byte[255];
System.out.print("清输入:");
System.in.read(buf, 0, 255);
System.out.print("您的输入如下:");
String input = new String(buf).trim();
int num = Integer.parseInt(input);
System.out.println(num);
} catch (IOException ioe) {
ioe.printStackTrace();
}
```
这里先将输入的字节数组转换成字符串,去掉两端的空格后再使用 Integer.parseInt() 方法将其转换成整型数。