battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.

battle programmers allianceLog in

the LivinGrimoire Artificial General Intelligence software design pattern forum

descriptionjava check if a number is in a range Emptyjava check if a number is in a range

more_horiz
using varargs I can also check if a group of numbers are ranged from
big to small.
something vb.net has : if n1<n2<n3
in java you had to do : if (n1<n2)&&(n2<n3))
moreover with more numbers the work increases, so...
kuchiyouse no jutsu :

Code:

public static Boolean bigTosmall(int... a)
{
   for (int i = 0; i < a.length - 1; i++) {
      if (!(a[i] > a[i + 1])) {
            return false;
      }
   }
   return true;
}


:hkn:

descriptionjava check if a number is in a range EmptyRe: java check if a number is in a range

more_horiz
get minimum or maximum from varargs array of integers

Code:

public static int miner(int... a) {
      int minimum = a[0];
      for (int i = 1; i < a.length; i++) {
         if (a[i] < minimum) {
            minimum = a[i];
         }
      }
      return minimum;
   }

   public static int maxer(int... a) {
      int maximum = a[0];
      for (int i = 1; i < a.length; i++) {
         if (a[i] > maximum) {
            maximum = a[i];
         }
      }
      return maximum;
   }
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply