Find the biggest of ‘n’ numbers using array in java

The following java program finds the biggest number in a collection of array.

import java.io.*;
class BiggestOfArray
{
int n;
BufferedReader br;
int a[];
void get()throws Exception
{
System.out.println("Enter n");
br=new BufferedReader(new InputStreamReader(System.in));
n=Integer.parseInt(br.readLine());
a=new int[n];

}
void pro()throws Exception
{
for(int i=0;i<n;i++)
{
System.out.println("Enter"+(i+1)+"element");
a[i]=Integer.parseInt(br.readLine());
}
int big=a[0];
for(int i=0;i<n;i++)
{
if(a[i]>big)
big=a[i];
}
System.out.println("Biggest of all number is"+big);
}
}
class BiggestOfArrayMain
{
public static void main(String arg[])throws Exception
{
BiggestOfArray obj=new BiggestOfArray();
obj.get();
obj.pro();
}
}

Leave a Reply

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