Help with function

Here is the function:

private static int CountHits(int userguess[], int adigit[], int digits,String args[]) throws Exception
{
      int Hits=0;
      int Misses=0;
      int x=0;

      for (x=0;x<digits;x++)
      {
            if (userguess[x]==adigit[x])
            {
                  Hits++;
            }
      }
//diagnostic
      String strChar = String.valueOf(args[0]);
                                                                        
if (strChar.equals("testing"))
      {
            
            x=0;
            System.out.print("DIAGNOSTIC:");
            for (x=0;x<digits;x++)
            {
                  System.out.print(adigit[x] + " ");  
            }

            System.out.print("\n");
            System.out.print("HIT RESULT:");
            for (x=0;x<digits;x++)
            {
                  if  (userguess[x]==adigit[x])
                  {
                        System.out.print("H ");  
                  }
                  else
                  {
                        System.out.print(". ");
                  }
            
            }
            System.out.print("\n");
      }
return Hits;

}

When I pass in this:
java Lab2 "testing"
everything works fine.

when i dont pass it in, I get an ArrayIndexOutOfBoundsException


how do i correct this?
pdidowAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
can u post your main
0
objectsCommented:
>      String strChar = String.valueOf(args[0]);

If thats the args from main then thatline will cause that error
because args will be empty
0
petmagdyCommented:
Hi pdidow,
//diagnostic

if(args.length >= 1)
{
     String strChar = String.valueOf(args[0]);
}
else
{
//ur descsion u may return for example
}


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.