Re: converting String type to char
From: Ryan Stewart (zzanNOtozz_at_gSPAMo.com)
Date: 02/21/04
- Next message: Thomas Schodt: "Re: converting String type to char"
- Previous message: Clayton McGow: "Re: Need Example Code for Image Swap"
- In reply to: Andrew Thompson: "Re: converting String type to char"
- Next in thread: Thomas Schodt: "Re: converting String type to char"
- Reply: Thomas Schodt: "Re: converting String type to char"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 20 Feb 2004 17:13:09 -0600
"Andrew Thompson" <SeeMySites@www.invalid> wrote in message
news:_4wZb.68624$Wa.67332@news-server.bigpond.net.au...
> David Heath wrote:
> > Steve,
> >
> > What I'm trying to achieve is to display "Welcome Mr./Ms. <name>"
> > based on user input to name and gender. This is the code
> >
> > public void welcome()
> > {
> > if(gender == "M") {
>
> You should use this form for String comparison..
>
> if(gender.equals("M")) {
>
> > System.out.println("Welcome Mr. " + name);
> > }
> > else{
> > System.out.println("Welcome Ms. " + name);
> > }
> > }
>
Except that he stated earlier that gender was a char. That should've been
included in this code sample. If that is still the case, then your problem
is that you're comparing a char to a String literal. You want:
if (gender == 'M') { ... }
The single quote or apostrophe denotes a char. Double quotes are always
String objects.
- Next message: Thomas Schodt: "Re: converting String type to char"
- Previous message: Clayton McGow: "Re: Need Example Code for Image Swap"
- In reply to: Andrew Thompson: "Re: converting String type to char"
- Next in thread: Thomas Schodt: "Re: converting String type to char"
- Reply: Thomas Schodt: "Re: converting String type to char"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|