find min number 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

4
3
Krish 100200 points

                                     Scanner input = new Scanner(System.in);
        // Minimum And Maximum 
        int count = 0;
        int min = 0;
        int max = 0;
        boolean bugSolved = true;
		/* or we can use :
        int min = Integer.MAX_VALUE;
        int max = Integer.MIN_VALUE;
        */
		
        while (true){
            int cnt = count++;
            System.out.print(&quot;Enter Number #&quot;+(cnt+1)+&quot;: &quot;);
            boolean isValid = input.hasNextInt();
            if(isValid){
               int num = input.nextInt();
               /* if (bugSolved){
                   bugSolved = false;
                   min = num;
                   max = num;
               }  # Just remove this condition and 
               	boolean (bugSolved) at the top, if you use 
               	int min = Integer.MAX_VALUE and int max = 
                Integer.MIN_VALUE */
                if (num &lt; min) {
                    min = num;
                }else if (num &gt; max){
                    max = num;
                }
            }else{
                System.out.println(&quot;Invalid input..&quot;);
                break;
            }
            input.nextLine();
        }
        System.out.println(&quot;Min Number : &quot; + min);
        System.out.println(&quot;Max Number : &quot; + max);

4 (3 Votes)
0
0
0
Lionel Aguero 33605 points

                                    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 &lt; arr.length; i++) {
            if (arr[i] &gt; max){ 
// array's index are compared with each other,
// whichever is greater will be assigned to max
                max = arr[i];
            }
            if(arr[i] &lt; 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

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
find minimum in java? how to find min and max number in java finding minimum and maximum numbers java minimum integer java integer minimum value java minimum number java how to find max and min number in java min value java integer java min max value min between number in java' min value integer java min integer value in java minimum number in java how to min and max value in java java minimum value min value java min max in value of integer in java minimum in java java minimum value int how to find max to min in java min number in java minimum integer in java minimum number and maximum without max or min in java how to find minimum and maximum value in java min int value java how to find the min of the given numbers in java from class how to find the min of the given numbers in java minimum value in java java int minimum min =min_int in java how to find minimum and maximum in java how to find min of 3 numbers in java how to get min integer in java java minimum integer min integer in java minimum value of int in java minimum value of integer in java min max int java minimum int java get the min value in java min value int in java min int in java min value in java min number java how to get minimum integer in java find min number in java find minimum number in java find min and max methods in java find min and max in java how to know min and max in java best way to get min max in java find min b/w two numbers in java using integer.max get max and min value in java min max in java how to find minimum value given value in java how to find minimum value from 4 given value in java java maximum and minimum number how to min max in java how to find maximum and minimum value in java returns the difference between the max value and the min value in java function that return min and max number java java min and max value number between max and min in java find min and max value java min and max java find max min from three number in java using method min and max number in java min and max in java java how to check for the lowest value of an array how to find the max value of an array in java java minimum value in array sorting of minimum value of data in java print max method java of array Write a Java program to find the maximum and minimum value of an array. find max value in array java max and min value of array in java get min value of int array java java find minimum value find min value in the array how to find the max and min value for list how to print minimum value in java how to find max and min in array in java get max value from array java determining the maximum value of a number java : Write a program to accept 20 integer elements and display the maximum and minimum element from the array. in java java calculate max value find minimum value array int minimum and maximum in array java java max and min values find min and max in array java write a java program to find the maximum and minimum value of an array arrays return max value java java find the lowest value of an array find min in array java java array find minimum value minimum and maximum value java find minimum value in array java use function find min value in array java java how to get a maximum value in array get minimum value in array java how to get minimum value from an array in java getting max and min of array in java getting max and min java How to get the maximum value of an array in java how to get the max number in an array java min max value java how to get the maximum value of integers in an array in java how to find the min of an array in java java find max in array of ints max and min in java array different ways to find min and max in an array java make an array getting max value java minimum and maximum values get max int of array java how to get minimum value from array in java find the maximum and minimum values in java how to find the min and max in a java array how to find minimum and maximum values in an array in java find min in a array in java check min of an array java how to get the max value in an array in java Java program to find the maximum and minimum value of an array. 9. Write a Java program to find the maximum and minimum value of an array. java how to return variable with the lowest value java min of array using array to find a minimum value in java get max value java how to find minimum in int array look for max value in array java java find max value in array how to find the max value in a array in java the easiest way to get the maximum number of an array java returns the minimum element in an array java find max of array numbers java how to check minimum and maximum number in an array in java how to check minimum and maximum number in a array in java how to fint lowest value in array java get maximum value of array java math min min array in java find max and min in array java get the lowest value from an array java how to find max of an array in java find the minimum and maximum values from array find minimum range in array java how find minimum in java java function to get minimum value in array how to get the max int in an array of ints in java java arrays min max finding return max of array java find maximum and minimum in array java java int array get min how to use min with an array in java how to find the maximum of a set of numbers in java how to find the minimum of a set of numbers in java get address of lowest number in array java how to find minimum in array in java sort array max to min java java method to find max value in array use set to find the minimum value java get min value array java Complete the maxValue method so that given the array nums, it will return the maximum value in the array. how to find min in java java minimum integer in array get lowest value in array java Write a Java program for finding the minimum and maximum from a given set of integers how to get the lowest value in an array java min value in java array min and max value in java how to select the lowest value in an array java find minimum in an array java how to find the minimum of an array in java find min no java how to calculate max and min in java how to calculate max and min in java' get max from array java print max value in array java java get min find the smallest value java in an array and loop java array maximum and minimum find max and min from input java how to assign max value to an array in java java logic to find min number in array how to sort an array highest value to lowest java get the minimum value in an array java finding min value array java min and max numbers in array java min and max value in array java maximum of all min java code maximum and minimum in array java how to find the maximum value of an array jav a java find minimum value in array how to find the maximum value in an array java find max and min in array in java Write a program in java to find the maximum and minimum element in input array. calc max in array java java get min max in arrat java print the max valeu java find max of int array finding the minimum value in java how to find min and max java best way to find minimum values in java return min value class java find minimum value in array java finding min and max in java finding min and max from given number in java
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source