In this tutorial, we are going to learn how we can Write a java program to find maximum element of an Array.
This is Question1 of Slip1.
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 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 :-
Thank You❤
Comments
Post a Comment