日期:2014-05-20  浏览次数:20831 次

高人请接招
请大家帮助一下新人,呵呵,多谢啦!
BufferedReader   stdin   =   new   BufferedReader(new   InputStreamReader   (System.in));
          int   c   =   stdin.read();
          System.out.println(c);
请问:
    如何修改上述代码,可使输出的数c是自己输入的数。

------解决方案--------------------
Scanner scanner = new Scanner(System.in);
int c = scanner.nextInt();
System.out.println(c);
------解决方案--------------------
Scanner才是1.5有的类吧,不能向前扩展
------解决方案--------------------
BufferedReader stdin = new BufferedReader(new InputStreamReader(
System.in));
int c=0;
Object c2=null;
while((c = stdin.read())> 0){
c2 = (char) c;
System.out.print(c2);
}
------解决方案--------------------
BufferedReader stdin = new BufferedReader(new InputStreamReader (System.in));
try{
int c = Integer.parseInt(stdin.readLine());
System.out.println(c);
}
catch(NumberFormatException nfex){
System.out.println( "输入的格式不对! ");
}
catch(Exception ex){
ex.printStackTrace();
}
------解决方案--------------------
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class AATest {
public static void main(String[] args){
BufferedReader stdin = new BufferedReader(new InputStreamReader (System.in));
try{
int c = Integer.parseInt(stdin.readLine());
System.out.println(c);
}
catch(NumberFormatException nfex){
System.out.println( "输入的格式不对! ");
}
catch(Exception ex){
ex.printStackTrace();
}


}
}

你需要将代码放入一个类中去才能运行呀?给出全部源代码,lz再尝试一下吧