lundi 27 avril 2015

How to make "if" condition change automatically depending on Command Line Argument in Java?

In my code, if condition should change depending on command line argument. For example in the code below:

int a = Integer.parseInt(args[0]);

for (int i = 0; i < 100000; i++)
{
  if (a == 2)
     if ((i % 25 == 0) || ((i+1) % 25 == 0)
       --do something
  else if (a == 3)
    if ((i % 25 == 0) || ((i+1) % 25 == 0) || ((i + 2) % 25 == 0))
       --do something
  ...
}

If command line argument increases, the number of conditions inside "if" should increase as well. So "if" condition depends on Command line argument which can be between 1 and 50. I need some optimal way to avoid writing "if" condition 50 times.

Aucun commentaire:

Enregistrer un commentaire