Created
April 7, 2013 16:19
-
-
Save blackraccoon000/5331159 to your computer and use it in GitHub Desktop.
数字重複のない日付探索プログラム
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package CalenderTest; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: Yutaka Fujii | |
* Date: 13/04/07 | |
* Time: 23:20 | |
*/ | |
import java.util.Calendar; | |
public class CalenderIncrement { | |
public static void main(String args[]){ | |
Calendar calendar = Calendar.getInstance(); | |
DisplayCalender dCalen = new DisplayCalender(); | |
ConflictCheck conflictNum = new ConflictCheck(); | |
// SetStart | |
int startYear = 0; | |
String sYear = String.format("%1$04d", startYear); | |
int startMonth = 1; | |
String sMonth = String.format("%1$02d", startMonth); | |
int startDay = 1; | |
String sDay = String.format("%1$02d", startDay); | |
String totalStart = sYear+sMonth+sDay; | |
int startDate = Integer.parseInt(totalStart); | |
// SetFinish | |
int finishYear = 2020; | |
String fYear = String.format("%1$04d", finishYear); | |
int finishMonth = 12; | |
String fMonth = String.format("%1$02d", finishMonth); | |
int finishDay = 31; | |
String fDay = String.format("%1$02d", finishDay); | |
String totalFinish = fYear+fMonth+fDay; | |
int finishDate = Integer.parseInt(totalFinish); | |
// カウンター | |
int counter = 0; | |
calendar.set(startYear,startMonth-1,startDay-1); | |
dCalen.formatCalendar(calendar); | |
System.out.println(startYear+"年"+startMonth+"月"+startDay+"日"+"から"); | |
System.out.println(finishYear+"年"+finishMonth+"月"+finishDay+"日"+"までの間で数字の被らない日付は下記の通りです。\n"); | |
for(int i=0;;i++){ | |
calendar.add(Calendar.DAY_OF_MONTH,1); | |
//// 何の数を把握しているか確認する | |
//// System.out.println("F"+dCalen.formatCalendar(calendar)); | |
// System.out.println("D"+dCalen.dispCalendar(calendar)); | |
// | |
String totalConflictCheck = conflictNum.cofChk(String.valueOf(dCalen.dispCalendar(calendar))); | |
// true or false | |
// System.out.println(totalConflictCheck); | |
if(totalConflictCheck.matches("true")){ | |
// System.out.println("×"); | |
} else { | |
// System.out.print(dCalen.formatCalendar(calendar)+" "); | |
System.out.print(dCalen.stCalendar(calendar)+" "); | |
counter++; | |
if(counter%10 == 0) System.out.println(); | |
} | |
if(dCalen.formatCalendar(calendar) == finishDate) break; | |
} | |
System.out.println("です"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package CalenderTest; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: Yutaka Fujii | |
* Date: 13/04/08 | |
* Time: 0:01 | |
*/ | |
public class ConflictCheck { | |
String cofChk(String argument){ | |
String str = argument; | |
boolean flg=false; | |
String[] confcheck = new String[argument.length()]; | |
for(int i=0;i<argument.length();i++){ | |
confcheck[i] = Character.toString(argument.charAt(i)); | |
} | |
for(int i = 0;i<argument.length();i++){ | |
for(int j =i+1;j<argument.length();j++){ | |
// String同士を比較 | |
if(confcheck[i].matches(confcheck[j])){ | |
flg=true; | |
} | |
} | |
} | |
if(flg){ | |
// 重複 | |
str = String.valueOf(flg); | |
} else { | |
// 大丈夫 | |
str = String.valueOf(flg); | |
} | |
return str; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package CalenderTest; | |
import java.util.Calendar; | |
/** | |
* Created with IntelliJ IDEA. | |
* User: Yutaka Fujii | |
* Date: 13/04/07 | |
* Time: 23:38 | |
*/ | |
public class DisplayCalender { | |
int formatCalendar(Calendar calendar) { | |
int year = calendar.get(Calendar.YEAR); | |
int month = calendar.get(Calendar.MONTH)+1; | |
int day = calendar.get(Calendar.DATE); | |
String sYear = String.format("%1$04d", year); | |
String sMonth = String.format("%1$02d", month); | |
String sDay = String.format("%1$02d", day); | |
String s = sYear+sMonth+sDay; | |
int calenderResult = Integer.parseInt(s); | |
return calenderResult; | |
} | |
int dispCalendar(Calendar dispcal) { | |
int year = dispcal.get(Calendar.YEAR); | |
int month = dispcal.get(Calendar.MONTH)+1; | |
int day = dispcal.get(Calendar.DATE); | |
// System.out.println(year+"年"); | |
// System.out.println(month+"月"); | |
// System.out.println(day+"日"); | |
String disString = String.valueOf(year)+String.valueOf(month)+String.valueOf(day); | |
int calenderResult = Integer.parseInt(disString); | |
return calenderResult; | |
} | |
String stCalendar(Calendar stCal) { | |
int year = stCal.get(Calendar.YEAR); | |
int month = stCal.get(Calendar.MONTH)+1; | |
int day = stCal.get(Calendar.DATE); | |
// System.out.println(year+"年"); | |
// System.out.println(month+"月"); | |
// System.out.println(day+"日"); | |
String disString = String.valueOf(year)+"年"+String.valueOf(month)+"月"+String.valueOf(day)+"日"; | |
String calenderResult = disString; | |
return calenderResult; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment