Converting int to string
- From: "Nick" <nickmacdonaldw@xxxxxxxxxxx>
- Date: 29 Oct 2005 09:35:54 -0700
Can anyone tell me how to develop this so that it shows the months ie
January, February etc when it runs.
class DayCounter {
public static void main(String[] arguments) {
int yearIn = 2004;
int monthIn = 1;
if (arguments.length > 0)
monthIn = Integer.parseInt(arguments[0]);
if (arguments.length > 1)
yearIn = Integer.parseInt(arguments[1]);
System.out.println(monthIn + "/" + yearIn + "has " + countDays(monthIn,
yearIn) + " days.");
}
static int countDays(int month, int year) {
int count = -1;
switch (month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
count = 31;
break;
case 4:
case 6:
case 9:
case 11:
count = 30;
break;
case 2:
if (year % 4 == 0)
count = 29;
else
count = 28;
if ((year % 100 == 0) & (year % 400 != 0))
count = 28;
}
return count;
}
}
.
- Follow-Ups:
- Re: Converting int to string
- From: Roedy Green
- Re: Converting int to string
- From: Rhino
- Re: Converting int to string
- From: billytcj
- Re: Converting int to string
- Prev by Date: Re: recommendations or a java development environment
- Next by Date: Re: confused
- Previous by thread: 3x3 (graphics) kernel
- Next by thread: Re: Converting int to string
- Index(es):
Relevant Pages
|
|