Java program to find the largest of element in the array

package array_largest;
import java.util.*;

public class Array_largest {

 
    public static void main(String[] args) {
   
        int num,i,max = 0;
        System.out.println("Enter the size of the array");
        Scanner sc= new Scanner(System.in);
        num=sc.nextInt();
       System.out.println("Enter the element in the array one by one");
       int array[]=new int [100];
       for(i=0;i<num;i++)
       {
           array[i]=sc.nextInt();
       }
       System.out.println("The entered element in the array is");
       for(i=0;i<num;i++)
       {
           System.out.println(array[i]);
     
       }
       System.out.println("The largest value in array is ");
       max=array[0];
       for(i=0;i<num;i++)
       {
         
           if(max<array[i])
           {
           max=array[i];
         
         
           }
       }System.out.println(max);
   
    }
 
 
}
OUT-
Enter the size of the array
5
Enter the element in the array one by one
78
65
12
45
32
The entered element in the array is
78
65
12
45
32
The largest value in array is 
78

Comments

Popular posts from this blog

cpanel exam CPSP Answers

How to install zimbra collaboration suite 8.8.11 on CentOS 7

awstats installation