Click to open Hangzhou Electric 2005
1, Split application: The string is divided into a number of characters as a string
2. Object-Oriented Programming
problem DescriptionGiven a date, the date of the output is the day ordinal of the year.
InputThere are several groups of input data, one row per group, the data format is YYYY/MM/DD, see sample input, and you can ensure that all input data is legal.
OutputFor each set of input data, the output line indicates that the date is the day ordinal of the year.
Sample Input
1985/1/202006/3/12
Sample Output
2071
Import Java.util.*;class mydate{int year, month,day;int[] months={0,31,0,31,30,31,30,31,31,30,31,30};p ublic 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 ());}}}
Hangzhou Electric 2005 (the first day?) ) Java string Water over