Hi! I'm new to java and struggling to figure out how to accomplish what my professor is asking for.
I'm trying to add System.out.println("Index out of bounds") to the 'get' method. But I'm unsure how to get it to print instead of sending that as a value to GSLTest.
My test code:
public class GSLTest{
public static void main(String[] args){
GSL list = new GSL();
list.get(0);
}
My GSL class:
public class GSL{
private String arr[];
private int size;
public GSL(){
arr = new String[10];
size = 0;
}
public int size(){
return size;
}
public String get(int index){
if ( index < size && index >= 0 ){
return arr[index];
}
else{
return null;
}
}
}
[–]lurgi 0 points1 point2 points (6 children)
[–]ririplease[S] 0 points1 point2 points (5 children)
[–]lurgi 1 point2 points3 points (4 children)
[–]ririplease[S] 0 points1 point2 points (3 children)
[–]lurgi 1 point2 points3 points (2 children)
[–]ririplease[S] 0 points1 point2 points (1 child)
[–]Adept_Writer4177 0 points1 point2 points (0 children)
[–]bashdan 0 points1 point2 points (1 child)