• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting a string based on another string  RSS feed

 
christopher temple
Greenhorn
Posts: 8
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone! I'm wanting to learn java, and I thought I would do so by making simple input books, since she is young and just learning to read. I am very new to java, so bear with me.

I wanted to ask a few simple questions off the start, name and sex, then, based on the sex, set some gender identity words like his, her, she and he. However, I'm not understanding how to change them once I initialize them.

This is what I have so far, if I set the genderId and genderId2 to null or anything else, that is what shows up in my text. How do I properly set the genderId strings based on the userSex string?
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One problem in the code is the use of == to compare Strings. You need to use the equals() method: string1.equals(string2)
 
christopher temple
Greenhorn
Posts: 8
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Norm Radder wrote:One problem in the code is the use of == to compare Strings. You need to use the equals() method: string1.equals(string2)


I changed it to look like this...



Now it is working fine, thank you very much
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Since the introduction of Java7, it has been possible to use Strings after case in a switch statement.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!