Hey guys,
Ok, basically, I had to copy an array of integers that another class sent to mine, and then do various things to it. The final thing I have to do is have the method sorted() check the array (localArray) to see whether or not it is sorted. (Ascending and Descending both count as sorted, no order what-so-ever doesnt.) The method then returns true if it is sorted, and false if it is not sorted. I sounds so simple for me, but I'm not sure why this isnt working. Here is the code I wrote:
public boolean sorted( ){
for(int i=0;i<50;i++){
if(localArray<localArray[i+1]){
return true;}
else if(localArray>localArray[i+1]){
return true;}
else{
return false;} //by this point, the return statement should be set.
}
//compiler wants a return statement here(apparently the set statment above does not count.
}
Any idea's? Thanks.
Ok, basically, I had to copy an array of integers that another class sent to mine, and then do various things to it. The final thing I have to do is have the method sorted() check the array (localArray) to see whether or not it is sorted. (Ascending and Descending both count as sorted, no order what-so-ever doesnt.) The method then returns true if it is sorted, and false if it is not sorted. I sounds so simple for me, but I'm not sure why this isnt working. Here is the code I wrote:
public boolean sorted( ){
for(int i=0;i<50;i++){
if(localArray<localArray[i+1]){
return true;}
else if(localArray>localArray[i+1]){
return true;}
else{
return false;} //by this point, the return statement should be set.
}
//compiler wants a return statement here(apparently the set statment above does not count.
}
Any idea's? Thanks.