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

Program Description Assignment #9 will be the construction of a program that rea

ID: 3684004 • Letter: P

Question

Program Description

Assignment #9 will be the construction of a program that reads in a sequence of integers from standard input until 0 is read, and store them in an array (including 0). This is done using iteration (choose one of for, while, or do while loop). You may assume that there will not be more than 100 numbers.

Then compute the minimum number, count even numbers, compute the sum of negative numbers, and count how many numbers in the array are greater than the number at the index 0, using recursion. Thus you will create recursive methods findMin, countEven computeSumOfNegative, and countGreaterThanFirst in Assignment9 class and they will be called by a main method.

Specifically, the following recursive methods must be implemented (These methods should not contain any loop):

    public static int findMin(int[] numbers, int startIndex, int endIndex)

    public static int countEven(int[] numbers, int startIndex, int endIndex)

    public static int computeSumOfNegative(int[] numbers, int startIndex, int endIndex)

    public static int countGreaterThanFirst(int[] numbers, int startIndex, int endIndex, int firstNumber)

If these methods are implemented using a Loop or any Static Variable, points will be deducted (from the test cases) even if your program passes test cases. DO NOT use any Static Variables.

The program should output the results of those calculations to standard output. Your program will continue to read in numbers until the number 0 is entered. At this point, the calculations will be outputted in the following format:

The minimum number is 0

The total count of even numbers is 0

The sum of negative numbers is 0

The total count of numbers that are greater than the first is 0

Note that the result values will be different depending on test cases (not always 0).

Do not output a prompt to query for the numbers. The number 0 is included in the sequence of numbers and should be included in all of your calculations.

Explanation / Answer

import java.util.*;
public class HelloWorld{
  
    Scanner read=new Scanner(System.in);
    static int min=Integer.MAX_VALUE;
    static int cnt=0;
    static int sum=0;
   public void readInput(int numbers[])
    {
    int flag=0,i=-1;
    System.out.println("Enter integers");
    while(flag==0)
    {
    i++;
    numbers[i]=read.nextInt();
    if(numbers[i]==0)
    flag=1;
    }
}
     int findMin(int[] numbers,int startindex,int endindex)
     {
         if(numbers.length==1)
         return numbers[0];
         else
         {
         if(numbers[startindex]<min)
         min=numbers[startindex];
         startindex++;
         if(startindex!=endindex)
         min=findMin(numbers,startindex,endindex);
      
         }
          return min;
     }
   
     int countEven(int[] numbers,int startindex,int endindex)
     {
         if(numbers[startindex]%2==0)
         cnt++;
         startindex++;
         if(startindex!=endindex)
         countEven(numbers,startindex,endindex);
         return cnt;
     }
   
     int computeSumOfNegative(int[] numbers,int startindex,int endindex)
     {
         if(numbers[startindex]<0)
         sum+=numbers[startindex];
         System.out.println(sum+"sads"+numbers[startindex]);
         startindex++;
         if(startindex!=endindex)
         computeSumOfNegative(numbers,startindex,endindex);
         return sum;
     }
   
    int countGreaterThanFirst(int[] numbers,int startindex,int endindex,int firstNumber)
     {
         if(numbers[startindex]> firstNumber)
         cnt++;
         startindex++;
         if(startindex!=endindex)
         countGreaterThanFirst(numbers,startindex,endindex,firstNumber);
         return cnt;
     }
   
     public static void main(String []args){
         int n[]=new int[100];
       HelloWorld test=new HelloWorld();
       test.readInput(n);
     System.out.println("Min elemnt is "+test.findMin(n,0,5));
    / System.out.println("Count of even numbers is "+test.countEven(n,0,5));
      System.out.println("Sum of negative numbers is "+test.computeSumOfNegative(n,0,5));
      cnt=0;
    System.out.println("Count of elemnts greater than first elemtns is "+test.countGreaterThanFirst(n,0,5,n[0]));
      
     }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote