Discuss / Java / 交作业

交作业

Topic source


public static int[] parseTime(String s) {

		// FIXME:

		if(s==null) {

			throw new IllegalArgumentException();

		}else {

			int [] hms  = new int[3];

			Pattern regex_p = Pattern.compile("([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])");

			Matcher regex_m = regex_p.matcher(s);



			 if(regex_m.matches()) {

				hms[0]=Integer.valueOf(regex_m.group(1));

				hms[1]=Integer.valueOf(regex_m.group(2));

				hms[2]=Integer.valueOf(regex_m.group(3));

//				for(int i:hms) {

//					System.out.print(i);

//					System.out.print(" ");

//				}

//				System.out.print("\n");

				return hms;

			}

			else {

				throw new IllegalArgumentException();

			}

		}

	}




  • 1

Reply