Hangzhou Electric 2005 (the first day?) ) Java string Water over

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.