I am trying to write a method which takes an int argument and returns the element of an array given if the passed int argument is less than the array length. I would appreciate it if someone can point me in the right direction.
Code:
String[] fruits = {"jan","feb","mar","apr","may","jun","jul","aug","sept","oct"};
public String getStr( int pos ){
String str;
if( pos <= fruits.length){
for( int i=0; i < fruits.length; ++i){
if(fruits[i] == pos){
str = fruits[pos];
}//IF
}
}//IF
else{
str = null;
}
return str;
}//METOD
posvsposition. Which one is it? Also, What do you thinkfruits[i]does?