Question

public static int max(int [] arr){ int max = arr[0]; for( int i = 1; i...

public static int max(int [] arr){
  int max = arr[0];
  for( int i = 1; i < arr.length; i++ )
    if( arr[i] > max ) max = arr[i];
  return max;
}

1) Provide an input value for arr that causes the method to throw an IndexOutOfBounds exception.
2) Provide an input value for arr that causes the method to throw a NullPointerException.

 
0 0
Add a comment Improve this question Transcribed image text
Answer #1
1) an input value for arr that causes the method to throw an IndexOutOfBounds exception.
int arr[] = {};


2) an input value for arr that causes the method to throw a NullPointerException.
int arr[] = null;
        
Add a comment
Know the answer?
Add Answer to:
public static int max(int [] arr){ int max = arr[0]; for( int i = 1; i...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int...

    must provide the following public interface: public static void insertSort(int [] arr); public static void selectSort(int [] arr); public static void quickSort(int [] arr); public static void mergeSort(int [] arr); The quick sort and merge sort must be implemented by using recursive thinking. So the students may provide the following private static methods: //merge method //merge two sorted portions of given array arr, namely, from start to middle //and from middle + 1 to end into one sorted portion, namely,...

  • Here is the indexOf method that I wrote: public static int indexOf(char[] arr, char ch) {...

    Here is the indexOf method that I wrote: public static int indexOf(char[] arr, char ch) {            if(arr == null || arr.length == 0) {                return -1;            }            for (int i = 0; i < arr.length; i++) {                if(arr[i] == ch) {                    return i;                }            }        return -1;       ...

  • Our 1st new array operation/method is remove. Implement as follows: public static boolean remove( int[] arr,...

    Our 1st new array operation/method is remove. Implement as follows: public static boolean remove( int[] arr, int count, int key ) { 1: find the index of the first occurance of key. By first occurance we mean lowest index that contains this value. hint: copy the indexOf() method from Lab#3 into the bottom of this project file and call it from inside this remove method. The you will have the index of the value to remove from the array 2:...

  • 5. What is the Big Oh method m2? public static void m2(int[] arr, int n) for...

    5. What is the Big Oh method m2? public static void m2(int[] arr, int n) for (int í = 1; í <= n- 1; i++) pM2(arr [i], arr, 0, i - 1); // end m2 private static void pM2(int entry, int[l arr, int begin, int end) int i- end; for(; (i 〉= begin) && (entry 〈 arr [i]); i--) arr [1 + 1] = arr L1] arr[i + 1] - entry; return // end pM2

  • Question 9 0 Consider the following method. public static String[] strArrMethod(String] arr) String[] result = new...

    Question 9 0 Consider the following method. public static String[] strArrMethod(String] arr) String[] result = new String(arr.length]; for (int j - 0; j < arr.length; j++) String sm = arr[i]; for (int k = j + 1; k < arr.length; k++) if (arr[k].length() < sm.length) sm - arr[k]; // Line 12 result[j] = SM; return result; Consider the following code segment. String[] test Two - {"last", "day" of "the", school","year"); String[] resultTrostrar Method(test Two) How many times is the line...

  • import java.util.Arrays; public class lab {    public static void main(String args[])    {    int...

    import java.util.Arrays; public class lab {    public static void main(String args[])    {    int arr[] = {10, 7, 8, 9, 1, 5,6,7};    int arr2[] = {9, 8, 7, 6, 5, 4, 3, 2, 1};    int arr3[] = {1, 3, 5, 3, 2, 6, 20};    quicksort(arr,0,arr.length-1);    quicksort(arr2,0,arr2.length-1);    quicksort(arr3,0,arr3.length-1);    System.out.println(Arrays.toString(arr));    System.out.println(Arrays.toString(arr2));    System.out.println(Arrays.toString(arr3));       }    private static int partition(int[] items,int low, int high)    {    int i=0;    int j=0;...

  • QUESTION: //Sort the array arr[] for (int i = 0; i < arr.length - 1; i++)...

    QUESTION: //Sort the array arr[] for (int i = 0; i < arr.length - 1; i++) { //outer int index = i; for (int j = i + 1; j < arr.length; i++) if (arr[j] < arr[index]) index = j; int smallerNumber = arr[index]; arr[index] = arr[i]; arr[i] = smallerNumber; }//for i In the array= 16 13 15 14 19 24 9 3, the index of the smallest number at the outer iteration 4 = Answer

  • Consider the following method. public static ArrayList<Integer mystery(int n) ArrayList<Integer seg - new ArrayList<IntegerO; for (int...

    Consider the following method. public static ArrayList<Integer mystery(int n) ArrayList<Integer seg - new ArrayList<IntegerO; for (int k = n; k > 0; k--) seq.add(new Integer(k+3)); return seq What is the final output of the following Java statement? System.out.println(mystery(3)); a. [1,2,4,5) b. [2,3,4,5) c. [6,5,4,3] d. [7, 7, 8, 8] e. [7,8,9, 8) O Consider the following method: public static int mystery(int[] arr, int k) ifk-0) return 0; }else{ return arr[k - 1] + mystery(arr, k-1):) The code segment below is...

  • 1. Write a complete program based on public static int lastIndexOf (int[] array, int value) {...

    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...

  • /** this is my code, and I want to invoke the method, doubleArraySize() in main method....

    /** this is my code, and I want to invoke the method, doubleArraySize() in main method. and I need to display some result in cmd or terminal. also, I have classes such as Average and RandomN needed for piping(pipe). please help me and thank you. **/ import java.util.Scanner; public class StdDev { static double[] arr; static int N; public static void main(String[] args) { if(args.length==0){ arr= new double[N]; Scanner input = new Scanner(System.in); int i=0; while(input.hasNextDouble()){ arr[i] = i++; }...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT