From: Randolph Wang <rywang@CS.Princeton.EDU>
Date: Tue, 13 Apr 2004 16:44:14 -0400
To: ehoa@Princeton.EDU
Cc: randy_class@CS.Princeton.EDU
Subject: Re: CS question
String [] foo;
declares an array of strings, not a single string of a certain length.
Your string declaration is wrong to begin with and it leads to all
kinds of problems. You declare a string with:
String foo;
And in all likelihood, you don't need anything like "foo = new ..."
You initialize an empty string with:
foo = "";
And you can concatenate things like:
foo = foo + "0";
The template of preorder should be
public void preorder(String prefix)
<BODY><P>Hi I had two questions<BR></P>
<P>1) I am having trouble concatenating "0" and "1" to the string for the preorder. The code i tried was some variation of this:</P>
<P>String1 += "1"; or String1 = String1 + "1";</P>
<P>the error i consistently got was incompatible types: it would say they "found: java.lang.string" but "required: java.lang.string[]"</P>
<P>and it pointed to the "+" sign.</P>
<P>2) I managed to get the bits to print out as was desired for part II without concatenation, however, the last two characters r and b had an extra one added to the end. I am not sure why they have that. I was wondering if you could possibly help me out or steer me in the right direction. Thanks, Ed</P>
<P>PS: I attached my program</P></BODY>
Re: CS question / Randolph Wang