很菜的问题,随便回答下给您20分了大哥快来.
public class test
{
public void display()
{
String name;
//some codes in here
System.out.println(name);
}
public static void main(String args[])
{
new test().display();
}
}
要在控制台输入数据保存到变量name里面
代码加到注释的位置
用System.in 怎么写啊
大哥教教啊我好菜好菜的
------解决方案--------------------public class test
{
public void display()
{
String name;
BufferedInputStream st1= new BufferedInputStream (System.in);
name=st1.read( );
System.out.println(name);
}
public static void main(String args[])
{
new test().display();
}
}
------解决方案-------------------- public void display()
{
String name;
byte[] buf = new byte[1024];
try {
System.in.read(buf);
name = new String(buf).trim();
System.out.println(name);
} catch (
IOException e) {
e.printStackTrace();
}
}