I have run this method through BlueJ in excess of 100 times to no avail. Please could someone correct my code
question:
/**
*A password-checking method called testNext has a signature:
public static String testNext(ArrayList<String> pins, String pin)
The method checks the String pin against each of the items in the ArrayList pins,
and if it finds a match it returns the next password in the ArrayList as a String,
otherwise it returns an empty String "" as a "rogue" (i.e. warning) value.
It also returns an empty String if the password found is the last one in the ArrayList.
Create the method.
Enter your answer (all the code between the braces that enclose the method) below:
public static String testPrevious(ArrayList<String> pins, String pin) {
String m = pin;
for (int i = 0; i < pins.size(); i++){
if (pins.get(i).equals(m)) {
if ( i == pins.size()-1) {
return "";
} return pins.get(i+1);
}
//else {return "";}
}
return "";
}
}
p.s as to the uncertainty of whether it is testnext or testprevious that is down to the poor quality question build. however it doesnt really matter which it is as i can try your code with (i+1) and (i-1) can't I.