Topic: 这里有什么错误?(System.in.read();)

  Print this page

1.这里有什么错误?(System.in.read();) Copy to clipboard
Posted by: zhuenhui
Posted on: 2005-08-13 15:47

import java.io.*;
public class rabbit{
public static void main(String args[])
{
String n = System.in.read();
System.out.println(n);
}
}

2.Re:这里有什么错误? [Re: zhuenhui] Copy to clipboard
Posted by: zhuenhui
Posted on: 2005-08-13 15:48

Post is deleted

3.Re:这里有什么错误? [Re: zhuenhui] Copy to clipboard
Posted by: bluepure
Posted on: 2005-08-13 16:09

//String n = System.in.read();

这还用得着问吗??

int n = System.in.read();

//关于read方法 public abstract int read() throws IOException;

要想读字符串,应该这样写:

try {
BufferedReader bf = new BufferedReader(new
InputStreamReader(System.in));
String n = bf.readLine();
system.out.printlnThumbs down;
}
catch (IOException ex) {
ex.printStackTrace();
}

4.Re:这里有什么错误? [Re: zhuenhui] Copy to clipboard
Posted by: zhangp_happy
Posted on: 2005-08-17 23:33

方法read()要 throws 出IOException!

5.Re:这里有什么错误? [Re: zhuenhui] Copy to clipboard
Posted by: brianlove
Posted on: 2005-08-22 02:24

使用System.in.read()方法必须要抛出异常,而且用于接收的变量类型不是String,应该用int类型,再用(char)转换进行输出就行了


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923