Max value in array

import java.util.*;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scn=new Scanner(System.in);
int n=scn.nextInt();
int a[]=new int[n];
int max=a[0];
for(int i=0;i<n;i++){
a[i]=scn.nextInt();

if(a[i]>-1000000000 && a[i]<1000000000)
{

if(a[i]>=max)
{
max=a[i];
}
}
}
System.out.println(max);

}
}
i modified my code but still 1 testcase not running

you have initialized max to 0 at the starting of the program . It may happen that all numbers are negative and your program prints 0 then.

No it is giving the maximum no in comilation but one test case went wrong can corret my code

sir respond to my query

I already told you. Initialize the max to Integer. MIN_VALUE

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.