Question
1. Write a complete program based on public static int lastIndexOf (int[] array, int value) { for (int i = array.length - 1; i >=
1. Write a complete program based on
public static int lastIndexOf (int[] array, int value) { for (int i = array.length - 1; i >= 0; i--) { if (array [i] == value) { return i; } } return -1;
write a method called lastindexof that accepts an array of integers and an integer value as its parameters and returns the last index at which the value occurs in the array. the method should return -1 if the value is not found. for example, in the array [74,85,102,99,101,85,56] the last index of the value 85 is 5
2. Write a complete program based on
public static int range (int[] array) { int min = array[0]; int max = array[0]; for(int i = 1; i < array.length; i++) { min = Math.min(min.array[i]); max = Math.max(max.array[i]); } return max - min + 1;
write a method called range that returns the range of values in an array of integers. the range is defined as 1 more than the difference between the maximum and minimum values in the array. for example if an array called list contains the value [36,12,25,19,46,31,22] the call of range[list] should return 35(46-12+1)you may assume that the array has at least one element
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