-
March 26th, 2011, 09:19 AM
#1
My if in java not doing what i expect it to do
I do not understand why Java does not end when my TOKEN string has BEGIN in the last five spots like the if says
Code:
if(((TOKEN.charAt(length-5)!='B')&&(TOKEN.charAt(length-4)!='E')&&(TOKEN.charAt(length-3)!='G')==true&&(TOKEN.charAt(length-2)!='I')==true&&(TOKEN.charAt(length-1)!='N')==true)
||((TOKEN.charAt(length-3)!='E')&&(TOKEN.charAt(length-2)!='N')&&(TOKEN.charAt(length-1)!='D')==true)||((TOKEN.charAt(length-4)!='N')&&(TOKEN.charAt(length-3)!='A')&&(TOKEN.charAt(length-2)!='M')&&(TOKEN.charAt(length-1)!='E')==true)
||((TOKEN.charAt(length-5)!='V')&&(TOKEN.charAt(length-4)!='A')&&(TOKEN.charAt(length-3)!='L')&&(TOKEN.charAt(length-2)!='U')&&(TOKEN.charAt(length-1)!='E'))==true)
I have alot more questions if anyone is able to help thanks for your time
-
March 26th, 2011, 09:34 AM
#2
Re: My if in java not doing what i expect it to do
the == true in my code was a test it's taken out now i'm not sure if i need them.
I code mostly in c++ my understanding is that this should work.
I just checking to see if TOKEN which should be #DOCUMENT BEGIN had BEGIN in the last five spots || END || NAME in my code i have many if's this is the top one and the first one which should not be entered.
-
March 26th, 2011, 09:42 AM
#3
Re: My if in java not doing what i expect it to do
if(TOKEN.indexOf("BEGIN")==-1)
Will this work?
-
March 26th, 2011, 09:47 AM
#4
Re: My if in java not doing what i expect it to do
it seems that my problem is || (OR) but i can't understand. why?
Code:
if((TOKEN.indexOf("BEGIN")==-1)||(TOKEN.indexOf("END")==-1)||(TOKEN.indexOf("NAME")==-1)||(TOKEN.indexOf("VALUE")==-1))
DOES NOT WORK
Last edited by Sleepking; March 26th, 2011 at 09:51 AM.
Reason: code tags were messed up
-
March 26th, 2011, 09:58 AM
#5
Re: My if in java not doing what i expect it to do
I just checking to see if TOKEN which should be #DOCUMENT BEGIN had BEGIN in the last five spots || END || NAME in my code i have many if's this is the top one and the first one which should not be entered.
if(TOKEN.endsWith("BEGIN") || TOKEN.endsWith("END") || ...
(I assume TOKEN is a java.lang.String)
I spent about 5 minutes trying to decifer your original code & gave up due to the confusing formatting, statements all jammed together with no spacing, redundant '= true' & redundant parenthesis. And, in the future, use punctuation when you communicate.
-
March 26th, 2011, 10:18 AM
#6
Re: My if in java not doing what i expect it to do
I'm sorry I am very new to Java. Thus, I don't understand how it should be formatted for people to understand it.
Now I have a problem where it returns.
#DOCUME
When it should return #DOCUMENT BEGIN.
By return I mean call the function lookup();
lookup normally will see if the TOKEN is a tag
now I have it just print out what it has then call lex();
Thanks for your help here is the if I have now.
Code:
if(TOKEN.endsWith("BEGIN") || TOKEN.endsWith("END") ||TOKEN.endsWith("NAME") ||TOKEN.endsWith("VALUE") )
(I think I punctuated well but if I did not tell me I guess.)
-
March 26th, 2011, 11:35 AM
#7
Re: My if in java not doing what i expect it to do
Never mind this works very well.
Thanks for your help.
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
|
Click Here to Expand Forum to Full Width
|