Posted: 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
Sponsor Sponsor
wtd
Posted: 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.
speX
Posted: Sun Oct 16, 2005 4:10 pm Post subject: (No subject)
ok.. so how would i make it select the first character.. of user input
rizzix
Posted: Sun Oct 16, 2005 5:02 pm Post subject: (No subject)
char strCheck = strInput.charAt(i);
strCheck == 'A'; // true if strCheck contains 'A'
Andy
Posted: Sun Oct 16, 2005 8:20 pm Post subject: (No 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