Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class maxPosSubSum{
- public static void main(String [] args){
- int N;
- Scanner in = new Scanner(System.in);
- N = in.nextInt();
- int numbers [] = new int[N];
- for(int i=0; i<N; i++)
- numbers[i] = in.nextInt();
- int sum, max = numbers[0];
- for(int i=0; i<N; i++){
- sum = 0;
- for(int j=i; j<N; j++){
- sum += numbers[j];
- if(sum > max)
- max = sum;
- }
- }
- System.out.println(max);
- }
- }
Add Comment
Please, Sign In to add comment