If you don't say more, look at the sample code directly below
Specific code:
Dayofweek4birthday.java package Com.gua;
Import Java.util.Calendar;
Import Java.util.GregorianCalendar;
Import java.io.*;
Import static java.lang.System.out;
/** * Created by 2gua on 2014/9/27.
* Dayofweek4birthday: Look at the specific date of your query is the day of the week, * For example, inquires who "birthday corresponds to the days of the week."
* * Public class Dayofweek4birthday {private string[] date;//Save input data: Years, months, date.
Calculates the day of the week for the date data entered.
private void Caculatedata () {GregorianCalendar GC = new GregorianCalendar ();
Final char[] Day_of_week = {' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six '}; int year = Gc.get (calendar.year);
From the current year.
Char week; for (int i = year; i<= year + integer.valueof (Date[0])-1; i++) {Gc.set (i, integer.valueof (date[1))-1, Integer
. valueof (date[2]);
Week = Day_of_week[gc.get (Calendar.day_of_week)-1]; OUT.PRINTLN (i + "year" + date[1] + "month" + date[2] + "number is Week" + Week + ".
");
}//Enter date data.
private void Inputdata () {InputStreamReader is = new InputStreamReader (system.in); BufferedReader br = new BufferedReader (IS);
try {out.print ("Enter the year range and date, format: The number of years in a few months (5 9 15), carriage return end:");
String in = Br.readline ();
Date = In.split (""); OUT.PRINTLN ("Input result:" + date[0] + "Number of years," + date[1] + "month" + date[2] + ".
"); catch (Exception e) {out.println ("Ah Oh, run wrong-_-.") sorry!
");
Finally {try {br.close ();
Is.close (); The catch (IOException e) {out.println ("IO error-_-. sorry!
"); }} public static void Main (string[] args) {Dayofweek4birthday dayofweek4birthday = new Dayofweek4birthday
();
Dayofweek4birthday.inputdata ();
Dayofweek4birthday.caculatedata (); }
}
Run, for example, to see from this year 5 years, the September 15 of the year is the day of the week.
The results are as follows:
Enter the year range and date, format: Number of years in a few months (5 9 15), enter end: 5 9
Input results: 5 years, September 15.
September 15, 2014 is Monday.
September 15, 2015 is Tuesday.
September 15, 2016 is Thursday.
September 15, 2017 is Friday.
September 15, 2018 is Saturday.
Process finished with exit code 0
Remember to close with the flow.
This is the practice of JDK 6, where you can use the new features in JDK 7 and JDK 8 to refactor the automatic resource management(ARM)
inputData()
method:
Enter date data.
private void Inputdata () {
try (bufferedreader br = new BufferedReader (new InputStreamReader (system.in))) { C17/>out.print ("Please enter the year range and date, format: Number of years in a few months (5 9 15), carriage return end:");
String in = Br.readline ();
Date = In.split ("");
OUT.PRINTLN ("Input result:" + date[0] + "Number of years," + date[1] + "month" + date[2] + ". ");
}
catch (Exception e) {
out.println ("Ah Oh, run wrong-_-.") sorry! ");
}
}
Of course, remember to set the module language level accordingly to JDK 7 or JDK 8,JDK 6 and below will not pass.
Summarize
The above is the entire content of this article, I hope the content of this article for everyone to learn or use Java can help, if you have questions you can message exchange.