System.in !!!
解决方案 »
- 問下枚舉enum啊
- 【类定义中,成员变量和成员方法之间,单独放一个println语句输出语句,能执行吗,这算什么?】
- 有关Java类中方法的一个问题
- 线程类Thread的问题:
- 求,java的CRC16校验程序!
- JFileChooser可以选择文件,那选择文件夹该如何实现呢?
- 谁能帮我看看这个Applet程序那里出错了?
- 请大虾推荐java的练习书籍
- 初学java,对throw 抛出个新异常不很理解。请哪为高人可以帮忙解释下么?谢谢
- java Oracle jjdbc 在eclipse中编写,无法成功连接Oracle
- 请问下面这段代码是怎么输出的,为什么
- 请教线程问题,怎样才能在一个线程里面等待另外一个线程执行以后,自己再执行呢?
System.in.read();
String in = reader.readLine();
String[] in2 = in.split(" ");
int[] result = new int[in2.length];
for (int i = 0; i < in2.length; i++) {
if (in2[i] != null) {
try {
result[i] = Integer.parseInt(in2[1]);
} catch (Exception e) {
}
}
}将上面代码做成函数,每次需要调用就可以了
cin太不安全,你要是达到上面这几行代码相同的安全效果用cin可有代码写呢...
换成
String[] in2 = in.split(" +");
更安全一点
代码没测试,有什么不对的地方请担待...
import java.io.*;public class KeyBoardReader{
private BufferedReader br;
public KeyBoardReader(){
br = new BufferedReader(new InputStreamReader(System.in));
}
public BufferedReader getReader(){
return this.br;
}
public void setReader(BufferedReader br){
this.br = br;
}
public double readdouble(){
double value = 0.0;
try{
String s = br.readLine();
System.out.println("s: " + s);
value = Double.parseDouble(s);
}
catch(Exception e){
System.out.println("Exception: " + e.getMessage());
}
return value;
}
public static void main(String[] args){
KeyBoardReader input = new KeyBoardReader();
System.out.println("please input double: ");
double radio = input.readdouble();
System.out.println("radio: " + radio);
}
}
byte aa[]=new byte[4];
PrintStream ps=new PrintStream(System.out);
ps.wirteTo(aa);