1. Design ideas: First of all think of the difference between the end and the unconnected? The difference between the last number and the previous number can be a new array;
Do you want to add other restrictions to the array to store the concatenated array?
2. Problem: The end-to-end array cannot be stored in an array like any other array.
4. Source code:
Package sub-array summation 2;
Import Java.util.Scanner;
public class Test {
public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner scan=new Scanner (system.in);
System.out.print ("Please enter the number of numbers in the array:");
int N=scan.nextint ();
int[] A=new int [n];
System.out.print ("Please input array:");
for (int i=0;i<n;i++)
{
A[i]=scan.nextint ();
}
int a1=findmaxsum (A,N);
int b,temp,i,sum=0;
for (b=1;b<n;b++)
{
TEMP=A[0];
for (i=1;i<=n-1;i++)
{
A[i-1]=a[i];
}
A[n-1]=temp;
if (Findmaxsum (a,n) >=sum)
{
Sum=findmaxsum (A,n);
}
}
int a2=sum;
if (A1>=A2)
{
SYSTEM.OUT.PRINTLN ("Maximum sub-array and:" + A1);
}
Else
{
SYSTEM.OUT.PRINTLN ("Maximum sub-array and:" + A2);
}
}
public static int findmaxsum (int a[],int N)
{
int sum=0;
int b=0;
for (int i=0; i<n; i++)
{
if (b<0)
B=a[i];
Else
B+=a[i];
if (sum<b)
Sum=b;
}
return sum;
}
}
Software Engineering Sub-array summation 2