Getting no output in arrays

Issue

This Content is from Stack Overflow. Question asked by Dibakar

”’
import java.util.*;

public class HelloWorld {

public static void main(String[] args) {

    int numbers[] = {-2, -3, 5, 7, 3, -1, 6};

    maxSubarraySum(numbers);

}

public static void maxSubarraySum(int numbers[]){

    int maxSum = 0;

    int currSum = Integer.MIN_VALUE;

    int prefix[] = new int[numbers.length];

    prefix[0] = numbers[0];

    
    for(int i=1; i<prefix.length; i++){

        prefix[i] = prefix[i-1] + numbers[i];

    }
    for(int i=0; i<numbers.length; i++){

        int start = i;

       for(int j=i; j<numbers.length; i++){

            int end = j;


           currSum = (start == 0)? prefix[end]:prefix[end]-prefix[start-1];

            if(maxSum < currSum){

                maxSum = currSum;

            }

        }

    }System.out.println("max is : " + maxSum);

}

}

”’
1.This code is not giving any output.
2.This should print the maximum sum but it’s not even showing any error.



Solution

Check the Answers

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?