HOW TO FIND LARGEST ELEMENT  OF AN ARRAY IN JAVA?


INPUT:-

import java.util.Scanner;
public class example{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int n[]= new int[6];
int i,t=0;

System.out.println("Enter the array element : ");
for(i=0;i<6;i++)
{
  n[i]=sc.nextInt();
}

System.out.println("Your element : ");
for(i=0;i<6;i++){
 System.out.print("\t" + n[i]);
 if(n[i]>t)
 t=n[i];

}

System.out.println("\n The largest element is : " + t); 
 
 }
}

OUTPUT:-