Reconizing Input


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Reconizing Input

  1. #1
    Join Date
    Apr 2003
    Posts
    3

    Question Reconizing Input

    for(int i=0; i<userInput.length(); i++){
    chemicalCh = userInput.charAt(i);

    if(Character.isLowerCase(chemicalCh)){
    splittedUserInput+=chemicalCh;
    String result = (String) chemicalElement.get(splittedUserInput);
    System.out.println(splittedUserInput+ " for " +result);
    }
    else(!splittedUserInput.equals("")){ chemicalArray.add(splittedUserInput.trim());
    splittedUserInput = userInput.substring(i,i+1);
    }
    }

    I use this arguement to make my program figure out how to reconize : XeCa
    Xe - Xenon
    Ca - Calcium

    but it doesn't reconize Single character anymore
    so if it is XeCaS

    It reconize Xe and Ca but not S?

    (I store all the character in Hastable, Xe as primary key and Xenon as secondary key)
    Can anyone help?
    Thanks

  2. #2
    Join Date
    Mar 2003
    Posts
    86

    splittedUserInput

    Why not do like that:

    for(int i=0; i<userInput.length(); i++)
    {
    chemicalCh = userInput.charAt(i);

    if(Character.isLowerCase(chemicalCh))
    {
    splittedUserInput += chemicalCh;
    String result = (String)chemicalElement.get(splittedUserInput);

    System.out.println(splittedUserInput+ " for " +result);

    splittedUserInput = "";
    }
    else(!splittedUserInput.equals(""))
    {
    splittedUserInput = chemicalCh;
    }
    }

  3. #3
    Join Date
    Apr 2003
    Posts
    3

    Lightbulb Thanks but........

    HI thanks but doesn't work.
    ChemicalCh is character and splitted user Input is String.

    I also mistype the sytax of the else statement
    here it is:

    for(int i=0; i<userInput.length(); i++){
    chemicalCh = userInput.charAt(i);

    if(Character.isLowerCase(chemicalCh)){
    splittedUserInput+=chemicalCh;
    String result = (String)chemicalElement.get (splittedUserInput);
    System.out.println(splittedUserInput+ " for " +result);
    }
    else{
    if (!splittedUserInput.equals(""))
    chemicalArray.add(splittedUserInput.trim());
    splittedUserInput = userInput.substring(i,i+1);
    }
    }


    any suggestion ? covert the string back to ch?
    or is there a better method?

    Thanks!
    Thanks

  4. #4
    Join Date
    Apr 2003
    Posts
    3

    Thanks

    no need to reply, I got it by adding another For loop, if and else statement to my exisitng code.
    Thanks!
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center