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


battle programming a forum for elite programmers with extreme will power to sharpen theire skills
 
HomeSearchRegisterLog in
 

 java check if a number is in a range

Go down 
AuthorMessage
kurosen
codding
codding
kurosen

Posts : 222
Join date : 2012-04-17

java check if a number is in a range Empty
PostSubject: java check if a number is in a range   java check if a number is in a range EmptySun May 03, 2020 7:16 am

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;
}

hadouken
Back to top Go down
kurosen
codding
codding
kurosen

Posts : 222
Join date : 2012-04-17

java check if a number is in a range Empty
PostSubject: Re: java check if a number is in a range   java check if a number is in a range EmptyWed May 06, 2020 3:59 am

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;
   }
Back to top Go down
 
java check if a number is in a range
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: battle programming-
Jump to: