Method One: Implement the package Test;import Java.io.file;import java.io.filewriter;import through an array java.io.ioexception;import Java.util.arraylist;import Java.util.list;import Java.util.random;public class ListData {public static void main (Strin G[] args) throws IOException {list<string> List = new arraylist<string> (); Random rd = new random (); String str1 = new string (); File File = new file ("E:\\date.txt"); FileWriter fis = new FileWriter (file); File File_sort = new file ("E:\\date_sort.txt"); FileWriter fis_sort = new FileWriter (file_sort); for (int i = 0; i < 444; i++) {str1 = (rd.nextint)% + 1) + "-" + (Rd.nextint (32)% 31 + 1); Fis.write (str1 + "\ r \ n");//List.add (STR1);//System.out.println (STR1); } fis.close ();//List.add ("8-2");//List.add ("8-2");//List.add ("8-2");//List.add ("5-2");// List.add ("5-2");//List.add ("5-2");//List.add("5-2");//List.add ("5-2");//List.add ("8-2");//List.add ("5-2");//List.add ("5-3");//List.add (" 5-4 "),//List.add (" 5-5 "),//List.add (" 5-6 ");//List.add (" 5-7 ");//List.add (" 5-8 ");//List.add (" 5- 9 ");//List.add (" 5-2 ");//List.add (" 5-2 ");//List.add (" 5-2 ");//List.add (" 5-2 ");//List.add (" 5-2 " );//List.add ("5-2");//List.add ("5-2");//List.add ("8-2");//List.add ("5-2");//List.add ("5-2"); List.add ("8-2");//List.add ("5-2");//List.add ("5-2");//List.add ("8-1");//List.add ("5-2");// List.add ("5-2");//List.add ("5-2");//List.add ("5-2");//List.add ("8-4");//List.add ("5-2");// List.add ("5-2");//List.add ("5-2");//List.add ("5-2");//List.add ("8-5");//List.add ("5-2");// List.add ("5-2");//List.add ("5-2");//List.add ("5-2");//List.add ("8-6");//List.add ("8-7");// List.add ("5-2");//List.add ("5-2");//List.add ("5-2");//List.add ("1-1");//List.add ("1-2");//List.add ("1-4");//Li St.add ("1-5");//List.add ("1-6");//List.add ("1-7");//List.add ("1-8");//List.add ("1-9");//List . Add ("1-5");//List.add ("1-6");//List.add ("8-3");//List.add ("1-1");//List.add ("1-2");//LIST.A DD ("1-4");//List.add ("1-5");//List.add ("1-6");//List.add ("1-7");//List.add ("1-3");// List.add ("1-12");//List.add ("1-13");//List.add ("1-14");//List.add ("1-15");//List.add ("1-16");// List.add ("1-17");//List.add ("1-18"); List.add ("1-1"); List.add ("1-2"); List.add ("1-4"); List.add ("1-5"); List.add ("1-6"); List.add ("1-7"); List.add ("1-3"); List.add ("1-12"); List.add ("1-13"); List.add ("1-14"); List.add ("1-15"); List.add ("1-16"); List.add ("1-17"); List.add ("1-18"); List.add ("1-20"); List.add ("1-21"); List.add ("1-22"); List.add ("1-23"); List.add ("1-24"); List.add ("1-25"); List.add ("1-26"); List.add ("1-27"); List.add ("1-28"); List.add ("1-29"); List.add ("1-30"); List.add ("1-31"); int[][] Date = new INT[12][32]; for (String str:list) {int ri = Integer.parseint (Str.split ("-") [1])-1; int yue = integer.parseint (Str.split ("-") [0])-1; Date[yue][ri] = 1; } for (int i = 0; i <; i++) {int[][] mark = new Int[1][2]; int k = 0; System.out.println ("--------" + (i + 1) + "month" + "---------------"); Fis_sort.write ("-------" + (i + 1) + "month" + "---------------" + "\ r \ n"); for (int j = 0; J <; J + +) {if (date[i][j] = = 1) {k++; if (k >= 7 && date[i][j + 1] = = 0) {mark[0] [0] = i; Mark[0][1] = j; System.out.println ((i + 1) + "Month" + (j + 2-k) + "Day, start continuous" + K + "Day"); Fis_sort.write ((i + 1) + "Month" + (j + 2-k) + "Day, start continuous" + K + "Day" + "\ r \ n"); for (int l = j-k + 1; l <= J; l++) {System.out.println ((i + 1) + "month" + (L + 1) + "Day"); Fis_sort.write ((i + 1) + "month" + (L + 1) + "Day" + "\ r \ n"); }}} else {k = 0; }}} fis_sort.close (); }}
Method Two: Implement package Test;import Java.io.file;import Java.io.filewriter;import Java.io.ioexception;import via TreeSet Java.util.arraylist;import java.util.hashmap;import java.util.list;import Java.util.map;import java.util.Map.Entry Import Java.util.random;import Java.util.treeset;public class Listdata_1 {public static void main (string[] args) thro WS IOException {list<string> List = new arraylist<string> (); Random rd = new random (); String str1 = new string (); File File = new file ("E:\\date.txt"); FileWriter fis = new FileWriter (file); File File_sort = new file ("E:\\date_sort.txt"); FileWriter fis_sort = new FileWriter (file_sort); for (int i = 0; i < 666; i++) {str1 = (rd.nextint)% + 1) + "-" + (Rd.nextint (32)% 31 + 1); Fis.write (str1 + "\ r \ n");//List.add (STR1);//System.out.println (STR1); } fis.close (); List.add ("1-1"); List.add ("1-2"); List.add ("1-4"); List.add ("1-5"); List.add ("1-6"); List.add ("1-7"); List.add ("1-3"); List.add ("1-12"); List.add ("1-13"); List.add ("1-14"); List.add ("1-15"); List.add ("1-16"); List.add ("1-17"); List.add ("1-18"); List.add ("1-20"); List.add ("1-21"); List.add ("1-22"); List.add ("1-23"); List.add ("1-24"); List.add ("1-25"); List.add ("1-26"); List.add ("1-27"); List.add ("1-28"); List.add ("1-29"); List.add ("1-30"); List.add ("1-31"); Remove to place the map hashmap<integer,treeset<integer>> map=new hashmap<integer,treeset<integer>> (); TreeSet Setvalue=null; for (String str:list) {int ri = Integer.parseint (Str.split ("-") [1]); int yue = integer.parseint (Str.split ("-") [0]); if (!map.containskey (Yue)) {setvalue=new treeset<integer> (); Setvalue.add (RI); Map.put (Yue, setValue); }else {//baohan setvalue=map.get (yue); Setvalue.add (RI); Map.put (Yue, setValue); }} for (Entry<integer, treeset<integer>> entry:map.entrySet ()) {//System.out.printl N ("Key =" + entry.getkey () + ", Value =" + Entry.getvalue ()); int Month=entry.getkey (); Treeset<integer> Value=entry.getvalue (); String v=value.tostring (). replace ("[", ""). Replace ("]", ""). ReplaceAll ("", "");//System.out.println (v); String []spldate=v.split (","); int []v_char_arr=new int[spldate.length]; for (int i=0;i<spldate.length;i++) {v_char_arr[i]=integer.parseint (spldate[i]); } int k=0;//for (int v1:v_char_arr) {//System.out.print (v1+ "");//// }//System.out.println ();// for (int i=0;i<v_char_arr.length-2;i+=1) {int v1=v_char_arr[i]; int v2=v_char_arr[i+1]; int v3=v_char_arr[i+2]; if (v2-v1==1) {k++;//System.out.println (V3-V2);//System.out.println (i+2+ "------"); if (k>=6&& (v3-v2) >1| | (i+2) ==v_char_arr.length-1) {System.out.println (month+ "month" + (V2-K) + "Day, start continuous" + (k+1) + "Day"); }//}else {k=0; }} System.out.println (); } }}