Wrong answer maximum subarray

while submitting it is showing wrong answer
code:
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int i,j;
for(i=0;i<t;i++)
{
int n=sc.nextInt();
int a[]=new int[n];
for(j=0;j<n;j++)
{
a[j]=sc.nextInt();
}
int max=0;
int newmax=0;
for(int p=0;p<n;p++)
{

 	max=max+a[p];
    newmax=Math.max(max,newmax);
	if(max<0)
	            max=0;
	max=newmax;			

}
   System.out.println(max);

}
}
}

do a dry run on {-2, -5, 6, -2, -3, 1, 5, -6} this array…we cant straightaway add a[p] in max…we need to check if max is less than 0 or it is greater than 0…(KADANES ALGO)…
refer to this code for correct order of statements

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.