My default test case is running fine but my rest of the test cases are not running what is wrong with the code

import java.util.*;
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String args[]) {

	int T = sc.nextInt();
	while(T!=0){
		summation();
		T--;
	}

}
public static void summation(){
	int n = sc.nextInt();
	int[] a = new int[n];
	int i = 0;
	while(i<n){
		a[i]=sc.nextInt();
		i++;
	}
	
	int sum=0;
	int temp=sum;
	for(int j=0;j<n;j++){
		temp+=a[j];
		if(sum<temp){
			sum=temp;
		}else{
			temp=sum;
		}

	}
	System.out.println(sum);

}

}

Hey ,initiate temp as int temp=sum; not 0
also if temp is -ve make it 0
that ll pass al the test cases
if this solves your doubt please mark your doubt as resolved :slight_smile:

but if I am making temp = sum then it is becoming +ve automatically why do I need to make it zero.