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);
}
}
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