// Maximum number finding
In this program you can find or search maximum number from an array. He we define an array of five elements and and then search the maximum number. Then display the number.
In this program you can find or search maximum number from an array. He we define an array of five elements and and then search the maximum number. Then display the number.
/**
* class ArrayMax here.
*
* @author (Khurshid Md Anwar)
*
*/
import java.io.*;
public class ArrayMax
{
public static void main(String args[])throws IOException
{
InputStreamReader ab=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(ab);
int a[]=new int[5]; // Creating array
int i,max;
// Inserting Array elements
System.out.println("Enter Five elements:");
for(i=0;i<5;i++)
{
a[i]=Integer.parseInt(br.readLine());
}
max=a[0];
for(i=0;i<5;i++)
{
if(a[i]>max)
max=a[i];
}
System.out.println("Max:"+max);
}
}
Output
Enter Five elements:
4
5
7
1
2
Max:7