To find the largest array of arrays and

Source: Internet
Author: User

Package Yunsuan;

public class Array {
public static void Main (string[] args) {

Int[] A = {1,-2, 3, 10,-4, 7, 2,-5};
int max = Maxsum (a);
SYSTEM.OUT.PRINTLN (max);
}

public static int Maxsum (int[] a) {
int out = 0;
int temp = 0;
for (int i = 0; i < a.length; i++) {
Temp = temp + a[i];
if (Temp > out)
out = temp;
if (Temp < 0)
temp= 0;
}
return out;
}

}

Import Org.junit.before;import org.junit.test;import Static org.junit.assert.*;/** * Created by Tony on 2017/3/17. */public class Arraytest {  private array array;    int sum []={1,-2, 3, -4, 7, 2,-5};    @Before public    void SetUp () throws Exception {      array =new array ();    }    @Test public    void Testmaxsum () throws Exception {        assertequals (18d,array.maxsum (sum), 0);}    }

To find the largest array of arrays and

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.