• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Setting a string based on another string

 
Greenhorn
Posts: 8
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 4893
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 76845
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
no wonder he is so sad, he hasn't seen this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic