Re: Brand new to Java student



Solved my own problem. Thanks for looking though.

I found that there is a 'string.equals' function. Who'd have thought
it!

On Jan 28, 2:24 pm, "Sandy" <s...@xxxxxxxxxxxxxx> wrote:
I am taking a course and we are using Java as our language. I haven't
used Java before so I am VERY new.

I have an application that I am writing that gets a string from user
input (called type). If the value of the string is "C" then I am
simply trying to recognize that so that I can make 'decisions'.

For some reason I cannot figure out how to tell what the 'value' of
the string is, although I can use the string. Here is my code:

<code>
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == submit)
{
startTemp = Double.valueOf(inField.getText()).doubleValue();
String type = new String();
type= inType.getText().toUpperCase().trim();
display.append(type);

if(type == "C" || type == "c")
{
display.append("Celsius");
}
}
}
</code>

the line: display.append(type);
works. It adds what ever is typed into the box to the text area. the
code in the if statement never executes.

I figure what ever I am doing wrong is probably stupid simple... but I
have never used Java so I don't see it. (Note I started with a case
statement only to find that you cannot do that with strings...)

Thanks for your help.

.



Relevant Pages

  • Re: Help me!! Why java is so popular
    ... String or StringBuffer? ... keep in mind I knew NOTHING about Java. ... The language accepted it, no warnings, and thus I ... in some native assemblers you can peruse the instruction ...
    (comp.lang.java.programmer)
  • Re: question about assigning null to a reference object
    ... String getAuthor() ... void setAuthor ... b.setTitle("Thinking in Java 4th Edition"); ...
    (comp.lang.java.help)
  • Re: Java questions: Urgent
    ... why I would expect almost any Java programmer to be able to answer ... Which is the main reason I "butted" in a bit.. ... on the characters in the String. ... > therefore naturally cover all the basics, or they have missed out badly ...
    (comp.lang.java.programmer)
  • Re: Using Cobol when writing CGIs for the OSU web server.
    ... string safe as well as make slow conversion (as bugs are found and ... The string type approach. ... Because no one has bothered to add it to the "offending" language. ... Java is certainly no replacement for C. ...
    (comp.os.vms)
  • MD5 solved differently, in an openplatform manner ... (Re: Problems with a DLL in ooRexx 4.0.0 under
    ... Rather than going for a particular Rexx function package, you could do something else: ... advantage of Java that is probably installed on your machine. ... returned Java byte array into a hexadecimal string with the help of Rexx. ... rxfuncquery for name: rxwibble was: 1 ...
    (comp.lang.rexx)