JAVA

星期一, 四月 10, 2006

display4.2

package sum;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class DateSecondTry
{
private String month;
private int day;
private int year;
public void writeOutput()
{
System.out.println(month+""+day+","+year);
}
public void readInput() throws IOException
{
System.out.println("Enter month,day.and year.");
System.out.println("Do not use a comma.");
BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in));
month=keyboard.readLine();
String d=keyboard.readLine();
day=Integer.parseInt(d);
String y=keyboard.readLine();
year=Integer.parseInt(y);
}

public int getDay()
{
return day;
}
public int getYear()
{
return year;
}
public int getMonth()
{
if (month.equalsIgnoreCase("january"))
return 1;
else if (month.equalsIgnoreCase("February"))
return 2;
else if (month.equalsIgnoreCase("March"))
return 3;
else if (month.equalsIgnoreCase("April"))
return 4;
else if (month.equalsIgnoreCase("May"))
return 5;
else if (month.equalsIgnoreCase("June"))
return 6;
else if (month.equalsIgnoreCase("July"))
return 7;
else if (month.equalsIgnoreCase("August"))
return 8;
else if (month.equalsIgnoreCase("September"))
return 9;
else if (month.equalsIgnoreCase("October"))
return 10;
else if (month.equalsIgnoreCase("November"))
return 11;
else if (month.equalsIgnoreCase("December"))
return 12;
else
{
System.out.println("Fatal Error");
System.exit(0);
return 0;
}
}
___________________________________________________________________

package sum;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class DemoOfDateSecondTry
{
public static void main(String[] args) throws IOException
{
DateSecondTry date=new DateSecondTry();
date.readInput();
int dayNumber=date.getDay();
System.out.println("That is the"+dayNumber+"th day of the month.");

}
}___________________________________________________________________
結果


Enter month,day.and year.

Do not use a comma.

7
6
2004
That is the6th day of the month.


Cookie

0 Comments:

发表评论

<< Home