-
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
-
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;
}
}
-
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
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks