Saturday, 26 April 2025

Contact Info

  • ADDRESS: 851, LG, Sector 3F, Sector 3, Vaishali, Ghaziabad, Uttar Pradesh 201010

  • PHONE: +91 7986794481

  • E-MAIL: contact@technicalspeaks.com

  • Home  
  • How to find max and min in array in java Using Scanner Class
- core java

How to find max and min in array in java Using Scanner Class

In java there is no any built-in functions for finding minimum and maximum values of an array, and to find that we would have to code by ourself; Before going to start Coding, if you don’t know the basics about Arrays in Java then watch this video below first: 1. Java Program to find the […]

How to find max and min in array in java

In java there is no any built-in functions for finding minimum and maximum values of an array, and to find that we would have to code by ourself;

Before going to start Coding, if you don’t know the basics about Arrays in Java then watch this video below first:

1. Java Program to find the minimum element of an array:

import java.util.Scanner;

public class ArrayMin{
public static void main(String[] args){
		
int n, min;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the no of elements in Array");
n = sc.nextInt();
int a[] = new int[n];
System.out.println("Enter elements in Array");
for(int i =0; i< n; i++){
a[i] = sc.nextInt();
}
min = a[0];
for(int i =0; i< n; i++){
if(min > a[i]){
min = a[i];
}
}
System.out.println("Minimum Element is " +min);

}	
}

Result:

how-to-find-min-element-in-array-java

2. Java Program to find the maximum element of an array:

import java.util.Scanner;

public class ArrayMin{
public static void main(String[] args){
		
int n, max;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the no of elements in Array");
n = sc.nextInt();
int a[] = new int[n];
System.out.println("Enter elements in Array");
for(int i =0; i< n; i++){
a[i] = sc.nextInt();
}
max = a[0];
for(int i =0; i< n; i++){
if(max < a[i]){
max = a[i];
}
}
System.out.println("Maximum Element is " +max);

}	
}

Result:

Leave a comment

Your email address will not be published. Required fields are marked *

About Us

Providing expert blogs on web, SEO, tech, YouTube, and more, helping readers stay updated and grow in the digital world.

Email Us: contact@technicalspeaks.com

Contact: +91 7986794481

Top Categories​

Sign Up for Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!