Java Program to find greatest Element in array

      No Comments on Java Program to find greatest Element in array

Greatest Element in array

This program illustrate the concept to find greatest Element in array.Array is a collection of similar types of element.It stores the elements in contiguous memory location.So to find the greatest element the program will compare elements one by one.

import java.util.*;
class scan
{
 public static void main(String arg[])
  { 
     int x,z=0,i,j;
       int y[]=new int[100]; 
     Scanner kb=new Scanner(System.in);
     System.out.println("Enter size of array");
     x=kb.nextInt();
     System.out.println("Enter elements in array");
     for(i=0;i<x;i++)
      {
	   y[i]=kb.nextInt();
	  }
     
     for(i=0;i<x;i++)
     { 
         if(y[i]>z)
		 {
			 z=y[i];
		 }			 
		
		
     }
     System.out.println("Greatest element is :- "+z);	 
  }
}

OUTPUT:

greatest Element in array


Comment below if you are facing any problem


Also read

Java simple program of defining array
Java Program to enter Elements of your choice in Array


Summary
Java simple Program to find greatest Element in array
Article Name
Java simple Program to find greatest Element in array
Description
This program illustrate the concept to find greatest Element in array.To find the greatest element in array the program will compare elements one by one.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

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