4. Problem 04: Day of Month
- Class-name: cDayOfMonth_<mssv>
- Requirment: print out the number days of a month.
- Input: Month (an integer) and Year (integer) from Console
- Output:
o If this month is not valid (không hợp lệ) then print out:
<month>/<year> is invalid year.
o Else: print out the number days of this month
<month>/<year> has <number-day> days.
- Note: becarful with leap year.
- Example:
o Ex1:
Input:
• Month: 13
• Year: 2009
Output: 13/2009 is invalid month.
o Ex2:
Input:
• Month: 8
• Year: 2010
Output: 8/2010 has 31 days.
o Ex3:
Input:
• Month: 2
• Year: 1200
Output: 2/1200 has 29 days.
This is code of myself.
import java.util.*;
public class test4 { /** * @param args */
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
int month, year;
System.out.print("Input moth month : ");
month=in.nextInt();
System.out.print("Input year year: ");
year=in.nextInt();
if(month<0&&month<=13){
System.out.print(month+"/"+year+" is invalid year ");
}
else{ if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){ System.out.print(month+"/"+year+" has 31");
}
if(month==4||month==6||month==9||month==11){
System.out.print(month+"/"+year+" has 30 ");
}
if(month==2&&(year%4==0&&year%100!=0||year%400==0))
{
System.out.print(month+"/"+year+" has is 28");
}
}
}
}
*Edited: to put a more describtive Topic Title
This post has been edited by pbl: 23 October 2009 - 08:51 PM

New Topic/Question
Reply




MultiQuote







|