Monday, August 4, 2014

How to find out the maximum number in array in java

How to find out the maximum number in array in java 
  import java.util.*;
 public class MaxArray
    {
    public static void main(String args[])
    {
           int []a=new int[20];
  int n,i,max;
          System.out.println("How many number insert in array..");
          Scanner sc=new Scanner(System.in);
         n=sc.nextInt();
    System.out.println("Enter the array element..");
  for(i=0;i<n;i++)
  a[i]=sc.nextInt();
max=a[0];
  for(i=0;i<n;i++)
  {
   if(max<a[i])
{
max=a[i];
}
}
  System.out.println("The Maximum Number is. "+max);
 }
}

No comments:

Post a Comment

Featured Post

What is JavaScript? What is the role of JavaScript engine?

  The JavaScript is a Programming language that is used for converting static web pages to interactive and dynamic web pages. A JavaScript e...