This program code describe how to find maximum in an array


Program Code :


import java.util.Scanner;
public class Array_Max {

public static void main(String[] args) {
Scanner scn=new Scanner(System.in);
int n,max,location=1;
int a[]=new int[100];
System.out.println("Enter the number of integer in array =");
n=scn.nextInt();
System.out.println("Input "+n+" integer");
for(int i=1;i<=n;i++){
a[i]=scn.nextInt();
}
max=a[1];
for(int i=1;i<=n;i++)
if(a[i]>max)
{
max=a[i];
location=i;
}
System.out.println("Maximum is "+max+" at position "+location);
}

}


Output : 

 Enter the number of integer in array =
5
Input 5 integer
47
15
84
35
46
Maximum is 84 at position 3



 
Top