Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 String Help!
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
speX




PostPosted: 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
Sponsor
sponsor
wtd




PostPosted: 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




PostPosted: 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




PostPosted: Sun Oct 16, 2005 5:02 pm   Post subject: (No subject)

char strCheck = strInput.charAt(i);

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




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: