← All resources

Write a program to input an array of size N and print the maximum value

import java.io.*;
public class max
{
    public static void main()throws IOException
    {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int n, a[], i, max;
        System.out.println("Enter the size:");
        n = Integer.parseInt(r.readLine());
        a = new int[n];
        System.out.println("Enter the values of the array:");
        for(i=0;i < n;i++)
        {
            a[i] = Integer.parseInt(r.readLine());
        }
        max = a[0];
        for(i=1;i < n;i++)
        {
            if(max < a[i])
            {
                max = a[i];
            }
        }
        System.out.println("Maximum value:"+max);
    }
}