Consider the following piece of code Consider the following

Consider the following piece of code:

Consider the following piece of code: String [] data ={\"100\", \"200\", \"222\", \"232\", null, \"250\"}; try {try{for (int i=0;i

Solution

Answer:

100
200
222
232

Unknown exception was encounterd.

Explanation:

data string array length is 6.

in for loop, we are iterating each string and displaying.

at i=0, String 100 will print

at i=1, String 200 will print

at i=2, String 222 will print

at i=3, String 232 will print

at i=4, Strign value is null. we aplied toString method on null object hence it will throw NullPointerException. Since we did not handle NullPointerException. The parent class Exception will catch it and handle it and print th emessage \"Unknown exception was encounterd.\".

If we have any value at i =4 then we would have got the exception ArrayIndexOutOfBoundsException.

Becuase or array size is 6 and index will startt from 0 to 5.

But in our case, we are running loop from 0 to 6. At i=6, we will get ArrayIndexOutOfBoundsException exception if we have value at i = 4.

Consider the following piece of code: Consider the following piece of code: String [] data ={\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site