Skip to content

SouthWind0826/-

Repository files navigation

package TEST;

import java.util.Scanner;

class Main {

public static  void main(String[] args) {
    int sz[] = new int[20],i,n;
    System.out.print("请输入整数个数n:");
    Scanner sc=new Scanner(System.in);
    n=sc.nextInt();
    if (n<=0)
        System.out.print("n应该是正整数,输入错误");
    else{
        for (i=0;i<n;i++)
        {
            System.out.print("请输入第"+(i+1)+"个整数:\n");
            sz[i]=sc.nextInt();
        }
    }
    System.out.print(add(n,sz));

}
public static int add(int n, int[] sz)
{
    int i,j,sum,max=0;
    for (i=0;i<n;i++)
    {
        sum=0;
        for (j=i;j<n;j++)
        {
            sum=sum+sz[j];
            if (max<sum)
                max=sum;
        }
    }
    if (max<0)
        max=0;
    return (max);
}

}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages