Write a java program that prompts the user to enter ten integer values and reads them into an array. The program should consist of the following methods: • a method named countOccurences that accepts an array of integer values and an integer search value. This method should return the number of occurrences of the integer search value. • a method named searchIndex that accepts an array of integer values and an integer search value. This method should return the index of the last occurrence of the search value. If the search value does not occur in the array the method should return -1. • a method named sumWithoutSmallest that accepts an array of integer values and returns the sum of all the values in the array except the smallest one
1) Write a java program that prompts the user to enter ten integer values and reads them into an array.
The program should consist of the following methods:
• a method named countOccurences that accepts an array of integer values and an
integer search value. This method should return the number of occurrences of the
integer search value.
• a method named searchIndex that accepts an array of integer values and an integer
search value. This method should return the index of the last occurrence of the search
value. If the search value does not occur in the array the method should return -1.
• a method named sumWithoutSmallest that accepts an array of integer values and
returns the sum of all the values in the array except the smallest one.
Invoke the above methods and demonstrate them in the program. Save the program as
ArrayOperations.java.
Here is a sample run:
Enter ten numbers: 2 3 4 4 2 7 4 5 6 3
Enter a search value: 4
The number 4 occurs 3 times in the array
The last occurrence of number 4 is at index position 6
The sum of all the values in the array except the smallest is:
36
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images