北京东城区公司:用JAVA语言编写数据的输入输出过程

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 10:31:22

输入用这个类
import java.io.*;
class Input
{
public static int inputInt()
{
String str="";
try
{ BufferedReader i=new BufferedReader(new InputStreamReader(System.in));
str=i.readLine();
}
catch(Exception e)
{
System.out.println(e);
}
return Integer.parseInt(str);
}
public static double inputDouble()
{
String str="";
try
{ BufferedReader i=new BufferedReader(new InputStreamReader(System.in));
str=i.readLine();
}
catch(Exception e)
{
System.out.println(e);
}
return Double.parseDouble(str);
}
public static String inputString()
{
String str="";
try
{ BufferedReader i=new BufferedReader(new InputStreamReader(System.in));
str=i.readLine();
}
catch(Exception e)
{
System.out.println(e);
}
return str;
}

}
这个inputInt()函数是输入整数的,inputDouble()是输入实数,inputString()是输入字符串的。
输出就用
System.out.println("要输出的内容");

System.out.print("your word");