Question
Java (MUST FOLLOW FORMAT OF TEMPLATE) Write a program that reads in a sequence of integers from standard input until 0 is read , and
Java (MUST FOLLOW FORMAT OF TEMPLATE)
Write a program that reads in a sequence of integers from standard input until 0 is read, and stores them in an array, similar to what you did in assignment 2. This part is done using iteration/loop . You may assume that there will not be more than 100 numbers.
Then compute the maximum number stored in the array, the count of even numbers (includes both postive and negative even integers), the number of -1 stored inside the array and compute the sum of numbers at odd indexes (i.e. 1, 3, 5, ...), using recursion. Thus you will create recursive methods findMax, countEven, countNegativeOne and computeSumAtOddIndexes in Assignment9 class and they will be called by a main method.
Specifically, the following four recursive methods must be implemented (These method should not contain any loop):
//(1) It finds the largest number in the partial array range from startIndex to endIndex public static int findMax([int[ ] numbers, int startIndex, int endIndex)
//(2) It counts the number of even integers in the partial arrya range from startIndex to endIndex public static int countEven(int[ ] numbers, int startIndex, int endIndex)
//(3 )It counts the number of -1 inside an array with "count" numbers, index ranges from 0 to count-1 public static int countNegativeOne(int[ ] numbers, int count)
//(4) It computes the sum of numbers at index 1, 3, 5, ..., inside a partial array with "count" numbers inside, index ranges from 0 to count-1 public static int computeSumAtOddIndexes(int[ ] numbers, int count)
If these methods are implemented using a loop, points will be deducted even if your program passes test cases.
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 largest number is 2 The total number of even integers is 1 The total number of -1 is 2 The sum of numbers at odd indexes is 2
Do not prompt the user for the numbers.
public class Assignment9 { /****************************************************************************** ***Complete the main() method. See above program description for details. ******************************************************************************/ public static void main (String[] args) throws IOException { } /************************************************************************************* ***(1)Complete the method. The method finds the largest number in the partial array ***range from startIndex to endIndex *************************************************************************************/ public static int findMax(int[ ] numbers, int startIndex, int endIndex) { } /************************************************************************************** ***(2)Complete the method. The method counts the number of even integers in the partial ***arrya range from startIndex to endIndex *************************************************************************************/ public static int countEven(int[ ] numbers, int startIndex, int endIndex) { } /************************************************************************************* ***(3)Complete the method. The method counts the number of -1 inside an array with *** "count" numbers, index ranges from 0 to count-1 *************************************************************************************/ public static int countNegativeOne(int[ ] numbers, int count) { } /************************************************************************************** ***(4)Complete the method. The method computes the sum of numbers at index 1, 3, 5, ... *** inside a partial array with "count" numbers inside, index ranges from 0 to count-1 ***************************************************************************************/ public static int computeSumAtOddIndexes(int[ ] numbers, int count) { } }// end of class Assignment9
INPUT: -1
2
-1
0
REQUIRED OUTPUT:
The largest number is 2 The total number of even integers is 1 The total number of -1 is 2 The sum of numbers at odd indexes is 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started