1、split的应用:将字符串以某某字符为界划分为多个字符串
2、面向对象的编程
1985/1/20 2006/3/12
20 71
import java.util.*; class MyDate{ int year ,month,day; int[] months={0,31,0,31,30,31,30,31,31,30,31,30}; public MyDate(String str){ this.set(str); } public void set(String str){ String[] s=str.split("/"); this.year=Integer.parseInt(s[0]); this.month=Integer.parseInt(s[1]); this.day=Integer.parseInt(s[2]); } public boolean isLeapYear(){ return year%400==0||year%4==0&&year%100!=0; } public int daysOfYear(){ if(isLeapYear()){ this.months[2]=29; }else{ this.months[2]=28; } int sum=0; for(int i=1;i<this.month;i++){ sum+=months[i]; } return sum+this.day; } } class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String str=sc.next(); MyDate d=new MyDate(str); System.out.println(d.daysOfYear()); } } }
原文:http://blog.csdn.net/u011479875/article/details/45078609