Array
1.design a method as below, which takes as an integer array as parameter, and that returns the smallest absolute value of the numbers contained in the array.
public static int minAbsoluteValue(int[] array){
xxxx
}
For example, the following piece of code should output the value 2.
int[] array = { -4, 5, 3, -4, 7, 8, -2 };
System.out.println(minAbsoluteValue(array));
2.design a method as below, which takes as an integer array and a integer variable as parameters, and that returns boolean value to represnt if the value of that variable exist in the array or not.
public static boolean contains(int[] array,int number){
xxxx
}
For example, the following piece of code should output the value true.
int[] array = { -4, 5, 3, -4, 7, 8, -2 };
System.out.println(contains(array,8));
3.design a method as below, which takes as an integer array and a integer variable as parameters, and that returns integer value to represnt the first index of that variable exist in the array, return -1 if it doesn't exist at all.
public static int indexOf(int[] array,int number){
xxxx
}
For example, he following piece of code should output the value 2 and value -1.
int[] array = { 3,-4, 7, 3, -4, 7, 8, -2 };
System.out.println(indexOf(array,7));
System.out.println(indexOf(array,4));

浙公网安备 33010602011771号