输入输出类

醉酒当歌 提交于 2020-01-29 04:27:01
import java.io.*;

public class KeyboardInput{

private final BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
public final synchronized int readInteger(){
String input="";
int value=0;
try{
input=in.readLine();
}
catch (IOException e){}
if(input!=null){
try{
value=Integer.parseInt(input);
}
catch(NumberFormatException e){}
}
return value;
}

public final synchronized long readLong(){
String input="";
long value=0L;
try{
input=in.readLine();
}
catch (IOException e){}
if(input!=null){
try{
value=Long.parseLong(input);
}
catch(NumberFormatException e){}
}
return value;
}

public final synchronized double readDouble(){
String input="";
double value=0.0D;
try{
input=in.readLine();
}
catch (IOException e){}
if(input!=null){
try{
value=Double.parseDouble(input);
}
catch(NumberFormatException e){}
}
return value;
}

public final synchronized float readFloat(){
String input="";
float value=0.0F;
try{
input=in.readLine();
}
catch (IOException e){}
if(input!=null){
try{
value=Float.parseFloat(input);
}
catch(NumberFormatException e){}
}
return value;
}

public final synchronized char readCharacter(){
char c=;
try{
c=(char)in.read();
}
catch (IOException e){}
return c;
}

public final synchronized String readString(){
String s="";
try{
s=in.readLine();
}
catch (IOException e){}
if(s==null){
s="";
}
return s;
}
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!