首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

很菜的有关问题,随便回答下给您20分了大哥快来.

2012-02-21 
很菜的问题,随便回答下给您20分了大哥快来.public class test{public void display(){String name//some

很菜的问题,随便回答下给您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();
}

}

热点排行