Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

find minimum 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
Comment

how to take the minimum value of an integer in java

// Java program to show
// the value of Integer.MIN_VALUE
  
class GFG {
  
    // Driver code
    public static void main(String[] arg)
    {
  
        // Print the value of Integer.MIN_VALUE
        System.out.println("Integer.MIN_VALUE = "
                           + Integer.MIN_VALUE);
    }
}
Comment

finding min and max from given number in java

 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("Enter Number #"+(cnt+1)+": ");
            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 < min) {
                    min = num;
                }else if (num > max){
                    max = num;
                }
            }else{
                System.out.println("Invalid input..");
                break;
            }
            input.nextLine();
        }
        System.out.println("Min Number : " + min);
        System.out.println("Max Number : " + max);
Comment

PREVIOUS NEXT
Code Example
Java :: java dimension 
Java :: mockito mock void methods 
Java :: gradle could not determine java versionAdd Answer 
Java :: java replace element in list 
Java :: java protected private public 
Java :: java priority queue 
Java :: printing multiple variables in java 
Java :: simple function java 
Java :: check folder for files java 
Java :: java create new object 
Java :: java constructor overloading 
Java :: raise error java 
Java :: java input string with spaces 
Java :: set solid color background android programatically in drawable 
Java :: indext of minimum element in an array in java 
Java :: android textview center align text programmatically 
Java :: install java using cmd 
Java :: how to remove all characters before a certain character from a string in java 
Java :: palindrome java 
Java :: java remove map 
Java :: How to efficiently reverse a singly linked list, in Java? 
Java :: convert array of char to string java 
Java :: do...while loop Java 
Java :: rider find and replace 
Java :: if and else on one line java 
Java :: java actionperformed 
Java :: java pattern check 
Java :: android studio setBackground 
Java :: how to create an array without knowing the size java 
Java :: For loop Java Example to Iterate an Array 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =