About 53 results
Open links in new tab
  1. Is Math.max(a,b) or (a>b)?a:b faster in Java? - Stack Overflow

    Jul 15, 2016 · 30 Math.max(a, b) is a static function (meaning no virtual call overhead) and will likely be inlined by the JVM to the same instructions as (a > b) ? a : b.

  2. math - Find the max of 3 numbers in Java with different data types ...

    @mlissner Yes, use a loop and a variable max, check for every variable whether or not they are larger than max, if so: set max to that variable. Assuming your n values are in an array of course.

  3. How to find maximum value of set of variables - Stack Overflow

    Feb 16, 2012 · I was wondering if anyone could help me find the maximum value of a set of variables and assign them to another variable. Here is a snippet of my code that may help with understanding …

  4. min (a,b) and max (a,b) equivalent in Java? - Stack Overflow

    Lol for the rep junkies - I'm surprised that this isn't a duplicate question, further, the first Google result for 'java min max' is the Math javadoc

  5. java - How to create max method that gets 4 numbers and returns the ...

    I'm trying to build a method that would get 4 numbers and returns the maximum number of them. I tried to write this code that gets 4 numbers but this not working: Input and output: double a = Ma...

  6. java - More convenient way to find the max of 2+ numbers ... - Stack ...

    Mar 30, 2013 · I want code that accepts more than 2 integers and prints out the biggest one. I used Math.MAX but the problem is that it accepts only 2 integers by default, and you can't print all the ints …

  7. java - Max/Min of three or more Integers if null values are allowed ...

    Apr 13, 2023 · Stream.of(value1, value2, value3) .filter(Objects::nonNull) .reduce(Math::max) .orElse(defaultValue); This creates a Stream containing the three values, filters out the nulls, calls …

  8. Java - limit number between min and max - Stack Overflow

    I want to return the number as long as it falls within a limit, else return the maximum or minimum value of the limit. I can do this with a combination of Math.min and Math.max. public int limit(int

  9. java - Finding the max of an int and a double? - Stack Overflow

    Mar 4, 2019 · First off, if you just use parameters of type double, Java will automatically perform a primitive conversion from int to double. Second, you can indeed use Math.max of compare the two, …

  10. Java Math.min/max performance - Stack Overflow

    Mar 31, 2014 · try ( final Benchmark bench = new Benchmark( "millis to max" ) ) { int max = Integer.MIN_VALUE; for ( int i = 0; i < array.length; ++i ) { max = OpsMath.max( max, array[i] ); // …