Hello in my assignment i was asked to make a max and min method comparing 2 elements of an array type T using the compareTo method and for some reason when the program gets to this chunk of code it stops and i cant find anything wrong with it? am i using compare to in the wrong way?
public T max() {
T max=myList[0];
if(size!=1){
for(int i=0;i<size;i++){
if(myList[i].compareTo(max)==1){
max=myList[i];
}
}
}
return max;
}
//method that gets the min number in the array
public T min() {
T min=null;
for(int i=0;i<myList.length-1;i++){
if(myList[i].compareTo(myList[i+1])==-1){
min=myList[i];
if(myList[i].compareTo(myList[myList.length])==-1){
min=myList[i];
}
}
}
return min;
}
Aucun commentaire:
Enregistrer un commentaire