Follow Us
Contribute
  • Register
Errorbase is a collaborative writing project, that aims to build the largest trouble-shooting guide about all kinds of error messages.

Categories

+1 vote
The following program gives the above error

 

public class Days
{
 public static void main(String args[])
 {
     int d=Integer.parseInt(args[0]);
  int m=Integer.parseInt(args[1]);
  int y=Integer.parseInt(args[2]);
  int flag=checkLeapYear(y);
  int x=y-1900;
                          x=x*365;
  x=x+((y-1900)/4);

  
  if ((flag==1)&&(m==1 || m==2))
   x=x-1;
  
  x=x+noOfDays(m,d);
  dayToDay(x%7);
 }
 
 static int checkLeapYear(int y)
 {
  int flag=0;
  if(y%100==0)
  { if(y%400==0)
    flag=1;
  }
  else
  { if(y%4==0)
    flag=1;
  }
  return flag;
 }
 
 static void dayToDay(int rem)
 {
  switch(rem)
  { case 0:System.out.print("Sunday");
    break;
   case 1:System.out.print("Monday");
    break;
   case 2:System.out.print("Tuesday");
    break;
   case 3:System.out.print("Wednesday");
    break;
   case 4:System.out.print("Thursday");
    break;
   case 5:System.out.print("Friday");
    break;
   case 6:System.out.print("Saturday");
    break;
  }
 }

 static int noOfDays(int m,int d)
 { int days=0;
  switch(m)
  { case 1:days=d;
    break;
   case 2:days=31+d;
    break;
   case 3:days=31+28+d;
    break;
   case 4:days=31+28+31+d;
    break;
   case 5:days=31+28+31+30+d;
    break;
   case 6:days=31+28+31+30+31+d;
    break;
   case 7:days=31+28+31+30+31+30+d;
    break;
   case 8:days=31+28+31+30+31+30+31+d;
    break;
   case 9:days=31+28+31+30+31+30+31+31+d;
    break;
   case 10:days=31+28+31+30+31+30+31+31+30+d;
    break;
   case 11:days=31+28+31+30+31+30+31+31+30+31+d;
    break;
   case 12:days=31+28+31+30+31+30+31+31+30+31+30+d;
  }  
  return days;
 }
}
requested by

1 Solution

0 votes
 
Best solution

You should check your input parameter, This Class' s Main method has an input variable 'String args[]', if you do not send this parameter or your input array does not have 3 String objects, you will get this error. In command line, call this Class like that :

java Days 21 10 1994

 

solved by
heyy thank u so much for this solution. I was also searching it from many times.
...