finding min and max from given number in java

Solutions on MaxInterview for finding min and max from given number in java by the best coders in the world

showing results for - "finding min and max from given number in java"
Christian
04 Nov 2016
1private static int findMin(int[] array) {
2		int min = array[0];
3		for(int i=1;i<array.length;i++) {
4			if(min > array[i]) {
5				min = array[i];
6			}
7		}
8		return min;
9	}
Jonas
29 Mar 2018
1public static double arrayMax(double[] arr) {
2    double max = Double.NEGATIVE_INFINITY;
3
4    for(double cur: arr)
5        max = Math.max(max, cur);
6
7    return max;
8}
Chiara
12 Jan 2018
1import java.util.Random;
2
3public class Main {
4
5public static void main(String[] args) {
6   int a[] = new int [100];
7   Random rnd = new Random ();
8
9    for (int i = 0; i< a.length; i++) {
10        a[i] = rnd.nextInt(99-0)+0;
11        System.out.println(a[i]);
12    }
13
14    int max = 0;          
15
16    for (int i = 0; i < a.length; i++) {
17        a[i] = max;
18
19
20        for (int j = i+1; j<a.length; j++) {
21            if (a[j] > max) {
22               max = a[j];
23            }
24
25        }
26    }
27
28    System.out.println("Max element: " + max);
29}
30}
Lilian
22 Aug 2017
1 Scanner input = new Scanner(System.in);
2        // Minimum And Maximum 
3        int count = 0;
4        int min = 0;
5        int max = 0;
6        boolean bugSolved = true;
7		/* or we can use :
8        int min = Integer.MAX_VALUE;
9        int max = Integer.MIN_VALUE;
10        */
11		
12        while (true){
13            int cnt = count++;
14            System.out.print("Enter Number #"+(cnt+1)+": ");
15            boolean isValid = input.hasNextInt();
16            if(isValid){
17               int num = input.nextInt();
18               /* if (bugSolved){
19                   bugSolved = false;
20                   min = num;
21                   max = num;
22               }  # Just remove this condition and 
23               	boolean (bugSolved) at the top, if you use 
24               	int min = Integer.MAX_VALUE and int max = 
25                Integer.MIN_VALUE */
26                if (num < min) {
27                    min = num;
28                }else if (num > max){
29                    max = num;
30                }
31            }else{
32                System.out.println("Invalid input..");
33                break;
34            }
35            input.nextLine();
36        }
37        System.out.println("Min Number : " + min);
38        System.out.println("Max Number : " + max);
queries leading to this page
get min from array javaget the max value in a double array javahow to find minimum value in array javahow to find the max in an array javafind maximum and minimum number in array javapic the max value java arrayjava how to check for the lowest value of an arrayhow to find the maximum value in an array java withoutfind max of an array in javathe easiest way to get the maximum number of an array javahow to print max of an array in javafind the min value in an array javajava array maximum valuejava get max from arraywrite a java program to print the sum of the maximum and the minimum element in the array in javahow to find max number with for loop java arrayjava min max arrayhow to get max and min in javamax length array javamin and max numbers in array javamaximum element of array javamaximum of all min java codefind max and min number in array javaget max number from arrraylist javamax and min in array in javajava max and min of an arrayfinding minimum value in array javajava min and max valuehow to find the min value in array in javahow to find minimum and maximum value in javahow to find max andd min in javamethod to find max from an array passed as argument javafind minimum and maximum values in a java arrayget minimum value in array javamax size of int array javafind max and min from input javafind max value in array javamax of int array javafinding min and max values in array javaint array find max javause set to find the minimum value javajava get array max valuefind minimum value in array in javafind max element in array javahow to find max element from an array of long in javacurrent max of an arra javahow to get the max and min number possible in javaarray min javahighest value class arrayjava code to get max value from arrayfind max and second max in array javahow to check minimum and maximum number in an array in javajava min max valuefind min from array in javamax value in array javajava return max of arrayposition of max value of array javafind min in int array java librarywhy 2b1 in array max javajava find min in arrayfunction to find max value in array javamath min min array in javahow to get the max value in array javaprint max variable in array javafind maxvalue in array javajava array min and maxmaximum number in an array in javamax of array javamax element in array function javahow to find max and min in array in javamaximum of a array javamax element index in array javafind max ones in an array javahow to check array min value in javafind the minimum and maximum values from arrayjava finding min and amx value in arrayfind min value in primitive array javajava max int in arrayfind minimum number in array javafind highest integer in array java min and max from array javajava find max using math max in arrayhow to find the min in an array javafind lowest value in array in javahow to return lowest value of array javamax numbe rin array javajava code for least value of int arrayjava method to min value in arrayjava array min valuemax element in array in javajava max function arrayfind min and max in array javajava how much does an int max array occupyfind minimum value array javaget the maximum value in array javafinding the max value in an array javamin element in array in javamaximum of an array in javahow to find the minumum value of a int array javamin value array javaget max value of int array javamin max of array javamaximum 2fminimum java with arraysfind minimum of array javahow to find the min and max in a java arrayhow to get the max int in an array on ints in javajava find minimum valuemax ele in array java inbuildmax amount in array javaminimum and maximum in array javafind min in an array javainbuilt function in java to find min of arrayarray max function in javafinding maximum number in array in javaarray string get max value javamethod to get max value of an array in javafind highest value in array javainbuilt function of java for finding max value in arrayfind the minum of n numbers in javahow to find the max of two arrays javaget max and min in array javamax number in array javajava index of max value in arrayjava how to get max value from an arrayfind max and min in array in javamaximum integer in an array javafind minimum calue in array javajava program to find max index of arrayarray api maximum valuereturn max of array javamin in java arraymaximum of array in java using inbuilt functionhow to get minimum value from array in javamax index 27 array javamax value of int 5b 5d array javafind min b 2fw two numbers in java using integer maxhow to find max in array javamax min value array javamax element javahow to get minimum value in a arraymin of an array javafind max value of array javajava min arrayjava max arrayget max int of array javaget min value from array javajava find max of int arrayhow to get minimum value from an array in javadefinining java int max in arrayfind min and max in array in javafind max in array java 8max value in array in javafind the max value of something in an array in javajava maximum and minimum numberhow to find minimum in array in javajava get minfind min and max values in javamaximum array element javahow to get the maximum element in a java array of integersjava calculate max valuemax and min element in array in javamin in array javaget minimum of array javasecond max from array in javafind min value in the arrayjava minimum and maximum values in arrayjava arrays min max findingjava array maxhow to find the maximum value of an array jav ajava find the minimum value in an arrayget max from array java using arraysfunctional java finding max in listhow to find maximum in array using function in javahow to calculate the min and max value program in javamin function in java arraymax elemnt in array in java methodhow to get max of array in javamaximum elements in a array can we make in javamax element in java arrayjava method to get max number in an arrayarray max javahow to find max of an array in javahow to get the max value in an arrayjava min of arraymaximum from array javafind maximum and minimum element in an array in javamaximum array in javahow to find max element in array in javaminimum value in a array javamax array size javanumber between max and min in javahow to find max of array in javamin and max in array javawrite a java program to find the maximum and minimum value of an array min and max in java arrayhow to calculate max and min in javahow get the max element of an array in javahow to find the max number in an array javajava largest value arrayget the max value of an double array javamax in int array javahow to find min and max in array javafind maximum and second maximum in array javajava 8 get maximum element from an arrayhow to find maximum and minimum value in array in javahow to find highest value in integer array javajava code to find out min in an arrayhow to find the highest and lowest number in an array using javamax element of array javawhat is the maximum size of an array in javajava array max valuejava int array maxjava min value in arraymin and max number in javajava get min max in arrathow to get max value from a list in javajava max int in an arraybest way to find minimum values in javajava array creat and maximum valuehow to find the maximum value in an array java without methodhow to get max int from array in javamaximum and minimum element in an array in javahow to make an array max value in javafind max equal element in array javaget maximum index in array javahow to get max value of array in javaget max value from array javajava maxlength array 3fprint max value in array javamin and max value in array java using for eachjava max value of arrayjava how to get highest value between multiple arrayswrite a java program for finding the minimum and maximum from a given set of integershow to get the max value in an array javamin and max values in javawhat happens when you get max and min of the same number in javamaximum element in an array can we make in javafind max element in array java using inbuilt functionmin max value javamin value in given data in javaminimum in array javafind max value in arrau javamax of all elements in the array javafunction finding max ocurences of element in array javaminimum value array javajava get minimum value in arraymethod to find max number in an array of ints javawrite a java program to find maximum and minimum element in an array java find min value in arrayfind maximum and minimum number in array in javahow to print max value in an array in javahow to get minimum and maximum values in 3 numbers in javaprogram that gives the minimum and maximum value of an array element in javahow to find max of given array using maz function in javamax of an array javafind min and max in array javajava array min max using inbuilt functionsmax in array in javahow to get the max int in an array of ints in javamax of array in javajava max of int arrayhow to get the maximum value of integers in an array in javamin element in array javamax array javajava array max int value and minjava min from arrayjava max of arrayjava array 2caxhow to find highest number in array in javaarray min value javahow to find the max and min value for listfind the smallest value java in an array and loopmethod to find min element in array in javamin and max value from the array in javadifferent ways to find min and max in an arrayjava int array get minmax value array javamin and max in javalargest value int 5b 5d array javaminimum value in array javamethod to find highest value in integer array javafind max of two numbers from an array javafind max value in string array javamax and min of array in java using inbuilt functionfunction to find max element in array in javajava in min and max valuefind min number in javahow to get the max value in an array in javamax int in an arrayfind the maximum element in array in java examplemax of array function in javahow to find max of array in java using exception handlinghow to find max score in array of java ints using collectionsfind max value in array java using math functionmin max in value of integer in javajava function to get minimum value in arrayjava make an array getting max valuehow to give max size to an arrayl in javacalculate min javalook for max value in array javamax element of the 1 d array javagetting max array in javaget the minimum value in an array javajava program to find min value in array for specific index built in functionjava array max value without collectionjava how to set max amount of elements in an arraymax from an array java 27java method finding the min of an arraymax array in javamaximum of array javawrite a program to get a maximum value in an array in javaminimum of array in javajava code for max element form arrayfind max in an array javahow to print minimum value in javafinding min value array javamaximum element in an array javajava find max index in arrayjava program to find min value in array built in functionmaximum integer value in array of javaget x max vlue javahow to calculate minimum using java program using arrayhow to find min number in array javamax value of an aray javafind max in an array using math max in javajava min function arraywrite a java program to find the maximum and minimum value of an arrayinteger min and max values javafind min in int array javajava program to find maximum number without using arrayminimum element in array javaselect max from int array javamaximum and minimum in an array in javaarrays max in javahow to get the min of an array in javamax int array javahow to find minimum value in array of string in javahow to find max from integers in array javaget max element of array javahow to min max in javajava max in an arraymax size of int array in javahow to find min value in arraypick the max value java arrayarray max size javahow to find min and maximum number in javaminimum in an array javareturn maximum value in array javaprogram to find maximum number in array in javafind max value in array with million records javahow to find max and min number in javausing array to find a minimum value in javajava find out max and min in arrayfinding min and max from given number in javamin max in array javajava program to find maximum and minimum number in an arrayjava find max and min in arraymax and min array number in javamax element out of an array javafind min and max value javaget max and min value in javaget max and min from array javajava max array elementfind max and min number in array in javaget max integer from array javafind maximum in java arrayget minimum number from array javajava array to find max and minjava find max using math max in arrayjava print the max valeufinding minimum of array in java functionmin max in array in java with methodfind min value in array javamax method java for arrayhow to find the max value of an array in javamin and max in an array javamax value of array in javahow to find max element in array in java simple wayfind min and max methods in javahow to find maximum number in array in javaarray find minimum value javajava get index of max value in arrayjava array minjava 8 min value in arrayin java how to get max number and min number in java8 3a write a program to accept 20 integer elements and display the maximum and minimum element from the array in javagetting max and min javahow to get minimum value in a array javajava program to find maximum and minimum number using arraymax element from array javaarray find max in javahow to sort an array highest value to lowest javahow to get the minimum of an int array in javato find max in an array of intjava find max value in arrayjava minimum integer in arrayjava max element of arrayfind the min and max in an array javamaximum value of array in javamaxmin of a array in javahow to min and max value in javafind max array javahow to find the min of an array in javahow to find minimum and maximum in javawrite a program in java to find the maximum and minimum element in an array find minimum in an array javamax and min number array in javahow to find min value in array in javasecond max value in array javasearch number between min and max javamin value of an array java 3a write a program to accept 20 integers elements and display the maximum and minimum element from the array in javaarray max element javafind maximum number in array in jvaget max number of indices in array javamax val array javajava arrays maxmax array length javahow to find max value in array java methodmethod to get minimum value of an array in javafind max from an array java codefind max of array numbers javamax array value javajava arrays find minwhat is max array size in javafind min value in int array in javajava find maximum value in arrayfinding the maximum of an array in javato find and print the maximum value stored in an array in javaget max value in array javahow to calculate a min number in a array in javahow to get the maximum value of an array in javamax in a array in javajava java when find min in array it returns only 0getting maximum element in array in java using inbuiltmax of int arraydetermining the maximum value of a number javamax item in array javahow to create the max size of an array in javahow to get max of an array in javamax array number in javahow to find the minimum of an array in javajava max element in arraymax and min of array in javamax element in array javafind min and max in javamin and max javahow to get the lowest value in an array javajava find max of array intmaximum of minimum program in javafinding minimum in an array javafind the minimum value of an array javamaximum value from int array javahow to find minimum value given value in javamin array javaarray max length javafinding the min of an arrray javacomplete the maxvalue method so that given the array nums 2c it will return the maximum value in the array get max of array javadetermine highest value in array java how to find min and max javamin and max value in javamaximum length of array in javamax element of array in javafind max and min of array in java returns the difference between the max value and the min value in javamethod for finding min in array javamin and max of array javamaximum value in array javaarray find max num in javafind max in array javajava how to get a maximum value in arrayjava program to find min elements in the arrayminimum from array javamin and max sum javahow to take the min of an array in javainbuilt function to find max in array in javamin number array in javamin array number in javahow to find min in javamaximum in an array javaget maximum and 2nd maximum number from array javafind min number in array using math in javafind min of array javajava find max in array of intshow to find the max and min of an array in javajava min in arrayhow to find minimum value in an array in javahow to find max value in java arrayarray max 28 29 in javahow to calculate min and max in javamin value in java arrayposition of max value of arr javajava find minimum int in arrayfind maximum value in array javato find max of n numbers of array javamin value in array javahow to return the minimum value in an array javahow to find minimum number in javafind minimum number in array in javajava get max int in arraymax size of array in ajvajava miniumum of arrayjava function that returns max value in arraysort array max to min javaget maximum value in int array javahow to find the max of an array javausing math min in an array javamax and min of array javamin of array in javafind max min from three number in java using methodjava find minimum value in arrayfind min no in array javaget min value of array javajava get min of arrayjava max int out of arrayhow to calculate max of array javaarray find max javafind minimum range in array javafinding the minimum value in javamax value of an array javafind min no javajava cant find min in arraymin of array javajava get max value from arrayfunction that return min and max number javajava max array sizehow to get the max values if i know the minimum in javaget max element from array javajava max value in arraymax of all elements of array in javamax value in int array javahow to find max and minimum value in an array in javaget max in array javafinding min and max in javareturns the minimum element in an array javajava get max of arrayjava program minimum and maximum values in arrayjava array maximumjava min of arrayhow to find minimum and maximum values in an array in javajava array maximum and minimumfind max value index in array javafunction to find max of an array in javajava get the int with the highest value in an arrayadd in min and max of an array javajava logic to find min number in arrayhow to find max number in a column of an array in javafind max integer in array javahow to find maximum and minimum value in javaget min value array javaarray function to get highest value javafind max in array in javahow to find the minimum value of an arrayreturn the maxvalue of an array javajava program to find maximum number in an arrayjava find max tabjava get max number in arrayto find max value in an array of intbest way to find max in array in javajava program to find max and min element in arrayjava maximum value in arraymax integer in array javajava array min max valuejava get min of two numbersarray min value javafind min number in array in javafunc to find max of an array in javagetting max and min of array in javafind max of primite array javamax int in array javahow to find max element from an long array in javafind max number in array javahow to find the maximum value in an array javamax value in array java functionmax and min value of array in javahow to get maximum number in array javajava max and min valuesjava 2 max number in an arrayget max value of matrix java9 write a java program to find the maximum and minimum value of an array min from array javawhat is the greatest number in java when getting min numberget max of an array javaprimitive array max in javahow to find minimum value in array in javafind min of array with sream javahow to find the minimum of a set of numbers in javagetting the max of an array in javafind maximum and minimum in array javaarrays return max value javahow to find the max element in an array in javahow to get the max number in an array javamax element in array java functionfunction to get the maximum value fro teh aray in java longjava find max in arrayhow to find minimum value from 4 given value in javamax element java arrayjava program to find min elememt in arraymin element of array javaget max value from list java 8java get largest value from arraywrite a java program to find maximum and minimum element in a array max array value java arraysjava array max methodfind max of array in javainbuilt function find min value from array javahow to assign max value to an array in javajava get min from arrayget maximum of array javahow to find min of 3 numbers in javamax 28array in javamethod to find maximum element in an array javafunction to find minimum value in an array in javato find max element in an array in javaprint max method java of arrayhow to find the min and max of an array javahow to use min with an array in javamaximum number of dimensions in a java array ismax of an array in javafind minimu and maximum values in arraymaximum number in array javamaximum and minimum java programhow to get the min value of an array in javahow to find max number in a array in javajava find max integer in arrayhow to find maximum in array in javafind minimum value in array java use function get min value in array javaget max value of array javaget the lowest value from an array javaget max number in array javaget lowest value in array javafind maximum integer in an array javajava maximum of arrayinteger max values javahow to find the maximum of a set of numbers in javajava program to find max and min numberjava max from arrayjava minimum and maximum valuesfind maximum value in array java methodjava find max in array quicklyfind min number in array javamax size of array in javamaximum size of array in javacheck min of an array javajava display numbers in order minimum to maximumminimum and maximum value javafind max value from an int array javamax and min in array javahow to use min mad fuction for arrays javamin and max value in array javareturn the max element of a array javamin max int javajava get max value from array built in methodfind the max number in an array javafinding maximum number out of 4 in without array in javahow to return the minimum value in an array in javaget max position in array javafind max and min values in an array of primitives using javajava find a min in an arraymin number in array javahow to get min from array in javareturn min of array javajava finding max of arrayhow to find lowest and highest value in array of integerhow take max value in array javafind the maximum and minimum element in an array in javaarray max javamaximum minimum element in array javaget the maximum value of a java arraylist max value javajava int max and min value in arrayfind minimum value array inthow to find the minimum value in an array javamin value of array in javajava get max value in arrayjava array find maxhow to get min and max value from array in javafind min in array javajava max number in arraysorting of minimum value of data in javamax and min ele in array javahow find minimum in javaarray min value java methodhow to find the lowest value in an array javamin and max in integer array javamaximum size of array possible in javahow to fint lowest value in array javajava how to return variable with the lowest valueget maximum value in array javaget max from int array javafinding the min of an array in javafind the max of an array javareturn min value class javaprint max number in array javamax min in array javamin of element in an array in javaget the min value in array javahow to get the max valud in array javamin array in javaways to find minimum value of arraymin max in javahow to find max to min in javahow to find min in array javaminimum and maximum value of array in javaindex of max value in array javagetting the maximum value of an array in javamax in an array javahow to get maximum number from an integer array in javasearch for the max and min value of an arraywhat is the maximum size of array in javahow to find maximum value from array in javayou have array of integers find the max value in the array in java mcqget the highest number in an array javaget maximum value of array javajava maximum elements to store in an arrayjava write a function to find the maximum in a float array return the index of the max value in an array javamax function in java for arrayjava get highest value in arraywrite a program in java to find the maximum and minimum element in input array get max value javajava get max element of arrayfind min in a array in javajava find the lowest value of an arrayfind max and min in array javamin value in an array javahow to select the lowest value in an array javamax in array javamin function in java for arraymax 28 29 3a highest value in the array javacalc max in array javajava array find minimum valuefind the maximum and minimum values in java java array 2cmaxfind minimum of array in javajava program to find the maximum and minimum value of an array how to find the minimum value in an array in javaarray find min in javahow to display minimum and maximum number in an arrayjava minimum value in arrayminimum number and maximum without max or min in javajava primitive array max valuesfast way to find max value from array javajava program to find min value in arrayget max from array javahow to find min and max value in array in javajava get max int from arrayfind min and max in whole array javaarrays max javajava get highest number in arraymin of an array in java find minimum value in array javajava method max arrayhow to check minimum and maximum number in a array in javafind max value in array java streamhow to find the min of the given numbers in javamax and min in java arrayfind max value array javafinding the highest value in a matrix javahow to calculate max and min in java 27how to find max ele in an array java functionfind minimum number in javahow to get the minimum of an arraymaximum in array javafind max of an array using loop in javato get max in array in javajava method to find max value in arrayfind max in integer array arrays javajava logic to get min of arrayget the maximum value of a java array int 5b 5darray max javabest way to get min max in javafind max value in javamax value out of an array javahow to find the highest value of an array in javafastest way to get max value in array javafinding minimum element in array javahow to know min and max in javaget max value array javamax number from array javajava max in arrayhow to find out the min and max in an array in javaprogram to find the maximum and minimum element in an array javaget address of lowest number in array javahow to get the maximum and minimum values of an array in javamaximum and minimum in array javahow to find the max value in a array in javahow to find the min value in a array in javajava get max value of arrayget maximum value in array java built in functionarray max value javamax integer from array javafind minimum in array javamax of arr in javafind max in long array javaget the max value out of an array in jav aget min value of int array javaget min of array javajava find minimum of an arrayhow to find minimum in int arrayis there any method which can find max in array in javajava find max value in array without collectionjava maximum number in an arrayfinding min and max from given number in java