Article ID: 173788
Article Last Modified on 8/25/2005
import java.io.*;
class App1_2
{
public static void main(String args[])
{
// uncomment the next line to make the program catch the exception:
// try {
int nMonth = Integer.parseInt(args[0]);
int nDay = Integer.parseInt(args[1]);
int nYear = Integer.parseInt(args[2]);
int nDayInYear = 0;
for (int nM = 0; nM < nMonth; nM++)
{
switch(nM)
{
case 4: case 6: case 9: case 11:
nDayInYear +=30;
break;
case 2:
nDayInYear +=28;
if (((nYear % 4) == 0) && ((nYear % 100) != 0))
{
nDayInYear++;
}
break;
default:
nDayInYear += 31;
}
}
nDayInYear += nDay;
System.out.print (nMonth + "-" + nDay + "-" + nYear);
System.out.println (" is day number "
+ nDayInYear
+ " in the year");
}
// uncomment this section to make the program catch the exception:
// } catch (ArrayIndexOutOfBoundsException e) {
// System.out.println("This program takes 3 parameters: ");
// System.out.println(" month day year.");
// }
}
Keywords: kberrmsg kbprb kbarttypeinf KB173788