• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

operator || cannot be applied to...

 
James Dark
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I wanted to know how to be able to place a statement that will check if either letters are equal to the letter stored in a[0]. I know I could break it up but would like to know how to do it in one line. Do you have to do ASCII keys or something?

//a[0] is a String array that contains either "C" or "c"
//e[0] is a String array that holds words
if (a[0] == ("C" || "c"))
e[0] = "Correct";

Any help is appreciated. Thanks.
 
Tim West
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
|| can only operate on booleans: what you give it on either side must evaluate to a boolean. If 'a' is an array of Strings:



I guess you could use == instead of .equals() here, but it's still generally a Bad Thing with Strings.


--Tim
 
James Dark
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again! You helped me save so many lines of code!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic