Solution of Maximum Subarray sum

here is my code
Scanner scn =new Scanner(System.in);
int n = scn.nextInt();
int [] a= new int[n];
for(int i=0; i<n-1; i++){
int k=scn.nextInt();
a[i]=k;
}
int sum=0;
for(int i=0;i<a.length-1; i++){
if(a[i]>0){
sum=sum+a[i];
}
}
if(sum>0){
System.out.print(sum);
}
else{
for(int i=0; i<a.length-1; i++){
for(int j=0; j<a.length-1-i; j++){
if(a[j]>a[j+1]){
int temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.print(a[a.length-1]);

	}

@harsh9368gupta_7f82345637b7cc20 you have to use kadane’s algorithm to do this question without TLE(Time limit exceeded). You will be taught tthis later in the course till then leave this question for now. and yes your O(N^2) solution is fine.

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.