java键盘输入问题

来源:百度知道 编辑:UC知道 时间:2024/06/27 05:41:46
import java.io.*;
public class EX_data{
String y; int year;
String m; int month;
String d; int day;

EX_data(){
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
System.out.print("Enter the year:");
y=input.readLine();
year= new Integer(y).intValue();
System.out.print("Enter the month:");
m=input.readLine();
month= new Integer(m).intValue();
System.out.print("Enter the day:");
d=input.readLine();
day= new Integer(d).intValue();
}
void show(){
System.out.println(year+"/"+month+"/"+day);
System.out.println(month+"-"+day+"/"+year);
System.out.println(day+"/"+month+"/&qu

文件的读写操作是会抛出 IOException 异常的
所以在做文件读写操作的时候应该用try...catch...语句包含起来.或者在方法最后添加 throws IOException

//////////////////////////////////
import java.io.*;

public class EX_data {
String y;
int year;
String m;
int month;
String d;
int day;

EX_data() throws IOException { //注意这里,我添加了throws IOException
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(reader);
System.out.print("Enter the year:");
y = input.readLine();
year = new Integer(y).intValue();
System.out.print("Enter the month:");
m = input.readLine();
month = new Integer(m).intValue();
System.out.print("Enter the day:");
d = input.readLine();
day = new Integer(d).intValue();
}

void show() {
System.out.println(year + "/" + month + "/" + day);
System.out.println