One more nooby Java question

B.def

Member
Jun 13, 2010
68
0
0
Sorry to bug everyone with these questions, so this is my last one.

Today in class we were assigned this problem.

Write a program that does the following
a. Declare a character and a string variable and assign initial values to them.
b. Print the values of both the variables on one line separated by a space character.
c. Use two Java statements to print your full name in one line.
d. Use only one statement to print your address in two lines.

What I dont understand is how to declare the string variable, what type of initial value he wants, and what it means by use two java statements to print my name.

Thanks in advance for any help.
 

B.def

Member
Jun 13, 2010
68
0
0
Thanks, but the link given doesn't really explain declaring a string and that's where I'm the most confused at. I don't even know where to begin.

This is my first guess

Code:
//Part a.
char x = 5;
String y = "This is a string";
//Part b.
System.out.println(x+" "+y);
//Part c.
System.out.print("Brendan ") System.out.println("DeForest");
//Part d.
System.out.println("XXXX Wayne St. \n Fort Wayne, IN");

I feel like I'm suppose to use the variables declared in part a for the rest of the steps.
 
Last edited:

Doublejr

Senior member
Jul 25, 2004
205
0
0
Looks like you got it correct minus some syntax. You need a ; between the printing your 1st and last. I would make your last name use println instead of print for formatting.

Should is be String instead of string?

Also in a public forum I would change your name and street to something else.

Edit: I see you made some corrections =D while I was responding.
 

B.def

Member
Jun 13, 2010
68
0
0
haha yes I caught myself in a few mistakes, but you verified my corrections to be right.
As far as my name and city I'm not too worried about, but thanks for the advice.

Thanks for your help though man.

Edit:Just verified with the professor and he says everything looks good! :D
 
Last edited: