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 odd integers, compute the sum of numbers that are larger than the first number in the array, and compute the largest even integer in the sequence using recursion. Thus, you will create recursive methods findMin, countOddNumbers, computeLargestEven, and sumOfNumbersLargerThanFirst 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 countOddNumbers(int[] elements, int startIndex, int endIndex)
public static int computeLargestEven(int[] elements, int startIndex, int endIndex)
public static int sumOfNumbersLargerThanFirst(int[] elements, int startIndex, int endIndex, int firstNumber)
If these methods are implemented using a Loop or any Static Variable, points will be deducted 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:
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.
Thanks for the question, here are the recursive methods without using any loops
=======================================================================
public static int findMin(int[] numbers, int startIndex, int endIndex) {
if (startIndex >= endIndex) return numbers[startIndex];
int number = numbers[startIndex];
int min = findMin(numbers, startIndex + 1, endIndex);
return number < min ? number : min;
}
public static int countOddNumbers(int[] elements, int startIndex, int endIndex) {
if (startIndex == endIndex) return elements[startIndex] % 2 == 1 ? 1 : 0;
if (elements[startIndex] % 2 == 1) return 1 + countOddNumbers(elements, startIndex + 1, endIndex);
else return countOddNumbers(elements, startIndex + 1, endIndex);
}
public static int computeLargestEven(int[] elements, int startIndex, int endIndex) {
if (startIndex >= endIndex) {
if (elements[startIndex] % 2 == 0) return elements[startIndex];
else return 0;
}
int number = elements[startIndex];
int largestEven = computeLargestEven(elements, startIndex + 1, endIndex);
if (number % 2 == 0) {
if (number > largestEven) return number;
else return largestEven;
} else {
return largestEven;
}
}
public static int sumOfNumbersLargerThanFirst(int[] elements, int startIndex, int endIndex, int firstNumber) {
if (startIndex >= endIndex) {
if (elements[startIndex] % 2 == 0 && elements[startIndex] > firstNumber) return elements[startIndex];
else return 0;
}
if (elements[startIndex] % 2 == 0 && elements[startIndex] > firstNumber)
return elements[startIndex] + sumOfNumbersLargerThanFirst(elements, startIndex + 1, endIndex, firstNumber);
else return sumOfNumbersLargerThanFirst(elements, startIndex + 1, endIndex, firstNumber);
}
==================================================================
Program Description: Assignment #9 will be the construction of a program that reads in a sequence...
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, compute the largest number among the numbers that are divisible by 2, count even numbers, and compute the...
Arizona State University - CSE205 Assignment #9 Due Date Friday, March April 3rd, 5:30pm Important: This is an individual assignment. Please do not collaborate. No late assignment will be accepted. Make sure that you write every line of your code. Using code written by someone else will be considered a violation of the academic integrity and will result in a report to the Dean's office. It must be submitted on-line (Course website). Go to "GradeScope" tab on Canvas -> CSE205...
Need help figuring this out Write a program that reads in a sequence of numbers (doubles) from standard input until 0 is read, and stores them in an array, This part is done using iteration (loop). You may assume that the maximum size of the array will not be more than 100. Your program computes the maximum number stored in the array, the count of negative numbers, and computes the sum of positive numbers, using recursion. You need to have...
Create a class called Reverse that reverses an array of integers. The class should have two method: - public static void reverse(int [] array) – Which calls the private recursive method, passing the array parameter and which two array elements should be swapped. - private static void reverseRecursive(int [] array, int startIndex, int endIndex) – Which swaps the two elements of the array parameter pointed to by the startIndex and endIndex parameters. The method should be called again, this time,...
In Java*
Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...
In Java
Write a program that reads an arbitrary number of 25 integers that are positive and even. The program will ask the user to re-enter an integer if the user inputs a number that is odd or negative or zero. The inputted integers must then be stored in a two dimensional array of size 5 x 5. Please create 3 methods: 1. Write a method public static int sum2DArray( int [1] inputArray ) The method sums up all elements...
What this Assignment Is About: Review on Java I topics, such as primitive data types, basic I/O, conditional and logical expressions, etc. Review on Java loops. Documentation Requirements to get full credits in Documentation The assignment number, your name, StudentID, Lecture number(time), and a class description need to be included at the top of each file/class. A description of each method is also needed. Some additional comments inside of methods (especially for a "main" method) to explain code that are...
A test harness program for testing sorting methods is provided with the rest of the textbook program files. It is the file Sorts.java in the ch11 package. The program includes a swap method that is used by all the sorting methods to swap array elements. Describe an approach to modifying the program so that after calling a sorting method the program prints out the number of swaps needed by the sorting method. Implement your approach. Test your new program by...
C++ assignment Write a program that reads a sequence of integers and prints the following: 1. The number of odd and even numbers of inputs Use a sentinel value to signal the end of inputs. If the sentinel value is the first you enter, give a message “NO input is entered!”. Input Validation: Do not accept a negative number.
In Python 3 - Write a program that reads a sequence of integer inputs from the user. When the user is finished entering the integers, they will enter a 'q'. There is no need to check if the entry is a valid integer. All integers in the test data (input) will be between -255 and 255. The program should then print: The smallest and largest of the inputs. The number of even and odd inputs (0 should be considered even)...