Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(100 pts) Write a program to find the smallest Positive integer that does not ap

ID: 646120 • Letter: #

Question

(100 pts) Write a program to find the smallest Positive integer that does not appear in the array and can not be formed by the sum of two numbers in an array. For this assignment implement the following function The function i.ssumof2 returns 1 if the number is sum of 2 elements in the array data and returns otherwise. size is the number of elements in the array. . The function in array returns 1 if the number appears in the array data and returns O otherwise. size is the number of elements in the array. 1 22I3 141311 0123456 Figure 1: Example An example is given in figure 1. 1.2,3 and 4 appear in this array. 4 can be formed as 4?1, 5 as 3+2, 6 as 3+3, 7 as 3+ 4 and 8 as 4+4 (it is ok to use a number twice). 9 does not appear in the array and it can not be formed as sum of 2 numbers in the array. So, 9 is the solution for this array. Read an array of size 7 from the user. compute the smallest positive integer that does not appear in the array or can not be formed by the sum of two numbers in an array, and print the result. Sample execution is given below Enter 7 numbers 1223431 Smallest No positive Integer = 9

Explanation / Answer

This is Answer:

import java.io.*;

import java.io.*;
public class MaxSubsum
{
public static int MaxSum(int[] array) {
int maxsum = 0;
int sum = 0;
for (int i = 0; i < array.length; i++)
{
sum += array[i];
if (maxsum < sum)
{
maxsum = sum;
}
else if (sum < 0)
{
sum = 0;
}
}
return maxsum;
}
public static void main (String[] args) throws IOException
{
int[] a=new int[25];
int num=0,i=0;   
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Number of element");
num=Integer.parseInt(reader.readLine());
System.out.println("Enter the array");
for(i=1;i<=num;i++)
{
a[i]=Integer.parseInt(reader.readLine());
}
int value = MaxSum(a);
System.out.println("The maximum sub sum is:"+value);
}
}