How To find maximum Element from an array using java |EasyCoding45

 In this Tutorial, we are going to learn how we can Write a java program to find maximum element of an array.


Program :-

import java.util.*;

class maximum

{

public static void main(String a[])

{

System.out.println("Enter Limit of Array :");

Scanner sc=new Scanner(System.in);

int n=sc.nextInt();

int arr[]=new int[n];

System.out.println("Enter Element of  an Array :");

for(int i=0;i<n;i++)

{

int elmt=sc.nextInt();

arr[i]=elmt;

}

int max=arr[0];

for(int i=0;i<n;i++)

{

if(max<arr[i])

{

max=arr[i];

}

}

System.out.println("Maximum Element of an Array :"+max);

}

}


Output :-



Comments