Computer Science Canada

String Help!

Author:  speX [ Sun Oct 16, 2005 3:57 pm ]
Post subject:  String Help!

i have this program....
code:
import TerminalIO.KeyboardReader;

public class Six {
        public static void main(String[]args) {
                String strInput;
                String strCheck;
                int intCount;
                KeyboardReader reader = new KeyboardReader();
                for (intCount = 1; intCount <=5; intCount++){
                        System.out.println ("Enter name "+ intCount + ":");
                        strInput = reader.readLine();
                        strCheck = strInput.charAt(1);
                        if (strCheck.equals("A") && strCheck.equals("I")){
                                System.out.println ("You are in Team 1");
                        }else if (strCheck.equals("J") && strCheck.equals("P")){
                                System.out.println ("You are in Team 2");
                        }else if(strCheck.equals("Q") && strCheck.equals("Z")){
                                System.out.println ("You are in Team 3");
                        }
                }
        }
}

and the problem i keep having is
code:
strCheck = strInput.charAt(1);
im not sure if im using it correctly.. but i get that one error and i duno wats wrong ><" plz help

Author:  wtd [ Sun Oct 16, 2005 3:59 pm ]
Post subject:  Re: String Help!

speX wrote:

and the problem i keep having is
code:
strCheck = strInput.charAt(1);
im not sure if im using it correctly.. but i get that one error and i duno wats wrong ><" plz help


strCheck is a String variable. charAt returns a character.

Author:  speX [ Sun Oct 16, 2005 4:10 pm ]
Post subject: 

ok.. so how would i make it select the first character.. of user input

Author:  rizzix [ Sun Oct 16, 2005 5:02 pm ]
Post subject: 

char strCheck = strInput.charAt(i);

strCheck == 'A'; // true if strCheck contains 'A'

Author:  Andy [ Sun Oct 16, 2005 8:20 pm ]
Post subject: 

in java, strings start at 0, which means if you input a single character, the string will not have a character at location 1, simply change the 1 to 0 and it should be fine


: