00:01
The question asks us to give an example of java code fragment that performs array reference, and it's possibly out of bounds.
00:07
If it is out of bounds, it should catch the exception and print error message.
00:11
Don't try, buffer overflow, attach to java.
00:15
So first we need a method to check if index is out of bounds.
00:19
If it's not out of bounds, then print the element at the index.
00:24
So we can just start by saying public, static, checkbound, an array of integers.
00:39
And so if we want to check a random array value then we can we'll just say our index is well we could we could if we wanted to check if it's possibly then we could say random rand equals new random class and then we could set an integer variable of the index that's potentially out of bounds equal to all uh random dot next int and then give it a range to go all the to 100.
01:25
And what we're really trying to get here is this try catch statement.
01:28
So try.
01:31
We want to try to print out what index we're on.
01:38
So system to out print lni, or in our case, index.
01:47
Sorry, we want to print the value so we can say array index...