I am trying to create a function that takes a string as function and returns an int.
public int convert (String input) {
int x = -1;
if (input == "one") {
x = 1;
}
else if (input == "two") {
x = 2;
}
else if (input == "three") {
x = 3;
}
return x;
}
The problem is, (assuming inputs will always be one of the three inputs), the function always returns -1. Ive tried:
- returning 0 instead of x
and:
public int convert (String input) { if (input == "one") { return 1; } else if (input == "two") { return 2; } else if (input == "three") { return 3; } return -1; }
Thanks guys.
0, not-1. I've edited it