Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max and min element of an array #52

Open
somya121 opened this issue Oct 14, 2021 · 0 comments
Open

Max and min element of an array #52

somya121 opened this issue Oct 14, 2021 · 0 comments

Comments

@somya121
Copy link
Contributor

import java.util.Scanner;
public class max_min
{
public static void main(String args[]){
Scanner in = new Scanner(System.in);

    System.out.println("Enter the length of array - ");
    int n = in.nextInt();
    System.out.println("Enter numbers in array - ");
    int array[] = new int[n];
    for(int i=0;i<n;i++){
        array[i] = in.nextInt();
    }
    int max =array[0];
    int min= array[0];
    for(int i=0;i<n;i++){
        if(array[i]<min)
        { min = array[i];
        }
        if(array[i]>max){
            max = array[i];
        }
    }
    System.out.println("Minimum - "+min);
    System.out.println("Maximum - "+max);        
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant