Answers for "max function in java"

3

max in array java

// Initializing array of integers 
        Integer[] num = { 2, 4, 7, 5, 9 }; 
// using Collections.min() to find minimum element 
        // using only 1 line. 
        int min = Collections.min(Arrays.asList(num)); 
  
        // using Collections.max() to find maximum element 
        // using only 1 line. 
        int max = Collections.max(Arrays.asList(num));
Posted by: Guest on September-24-2020
0

find max in java

int[] arr = {2, 3, 4, 5, 6, 7, 8, 9,};
        int max = arr[0]; // max tanimliyorsun
        int min = arr[0];  // min tanimliyorsun

        for (int i = 0; i < arr.length; i++) {
            if (arr[i] > max){ 
// array's index are compared with each other,
// whichever is greater will be assigned to max
                max = arr[i];
            }
            if(arr[i] < min){ 
//array's index are compared with each other,
// whichever is smaller will be assigned to min
                min = arr[i];
            }
        }
        System.out.println(max); // 9
        System.out.println(min);  // 2
Posted by: Guest on June-09-2021
0

Max in Java

int a = 3;
int b = 6;
System.out.println(Math.max(a, b));// will print 6
Posted by: Guest on October-14-2021
0

max_value in java

(stores the maximum possible value for any integer variable)
    public static void main(String[] arg)
    {
  		System.out.println("Integer.MAX_VALUE = "
                           + Integer.MAX_VALUE);///output :-2147483647
    }
}
Any integer variable cannot store any value beyond this limit
Posted by: Guest on June-04-2021
1

math max java

//	Math.max(a, b);
dataType max(dataType num1, dataType num2)
The datatypes can be int, float, double or long.

Parameters : The function accepts two parameters num1 and num2 
among which the maximum is returned.
Posted by: Guest on May-15-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language