BufferedRead br = new BufferedRead(new InputStreamReader(System.in));
String s = br.readLine();如果坚持用cin,可以用native方法,不过我没用过,书上这么写的,俺也是大菜鸟。
String s = br.readLine();如果坚持用cin,可以用native方法,不过我没用过,书上这么写的,俺也是大菜鸟。
调试欢乐多
-----------
class console
{
public static String readLine()
{ int ch;
String r = "";
boolean done = false;
while (!done)
{ try
{ ch = System.in.read();
if (ch < 0 || (char)ch == '\n')
done = true;
else if ((char)ch != '\r') // weird--it used to do \r\n translation
r = r + (char) ch;
}
catch(java.io.IOException e)
{ done = true;
}
}
return r;
}
}
public class ReadLine
{
public static void main(String[] args)
{
System.out.println("Please input a string :");
String s=console.readLine();
System.out.println("What you have input is:\n"+s);
}
}