Indexing Integers of a Class
in
Programming Questions
•
1 year ago
Hey
I have created this class, and a part of it returns an integer based on specific conditions.
I pass a string to the constructor that defines a user. I take this argument and want to check it from the string array of this class. However, it doesn't return the correct result.
Any ideas of what's the matter?
- class MessageClass {
- String[] index = {"One", "Two", "Three"};
- String user;
- MessageClass (String user) {
- this.user = user;
- }
- int indexNumber() {
- int checkTheName = 0;
- for (int i = 0; i < 3; i++) {
- if (user.equals(index[i]) == true) {
- checkTheName = i;
- } else {
- checkTheName = 0;
- }
- }
- return checkTheName;
- }
- }
1