wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Declaring strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Declaring strings" Watch "Declaring strings" New topic
Author

Declaring strings

Julie Montoya
Greenhorn

Joined: May 27, 2002
Posts: 3
I don't know how to declare a string. My homework assignment is to "declare a string called name setting it equal to my full name and output i using a single println() statement." And "declare 3 strings named fname, mname, and lname, assigning each of my three names to one of the strings. Output my entire name using a single println() statement by using concatentation." Could someone please help me???


Julie
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Do you know how to declare *any* variable and assign it a value? Do you know how to write a basic "hello world" java program?
People will be more than happy to help you , but they won't do your homework for you. If you have specific questions about how to perform a particular task, you'll get more responses. Also, if you can post any code you've written so far, that will also help.
Help us help you!!


Rob
SCJP 1.4
Julie Montoya
Greenhorn

Joined: May 27, 2002
Posts: 3
I do know how to do the "Hello World". I'm only in my 2nd week of programming & I'm not expecting anyone to do my homework for me, it's just that my instructor did not go over how do declare a string. What I have so far is:

[ May 27, 2002: Message edited by: Dirk Schreckmann ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
This is how you declare and define String variables in Java:
String someVariableName = "Some text" ;
When you want to display the value of this variable using System.out.println, just use the name of the variable instead of the String literal itself:
System.out.println( someVariableName );
Hopefully you can now figure out how to do this very same thing three more times using the identifier names and values that you've been instructed to use.
Any luck?
P.S. I'm surprised if the course book doesn't describe how to do this very thing somewhere in the first couple of chapters.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Julie Montoya
Greenhorn

Joined: May 27, 2002
Posts: 3
Thank you very much! I think I was making it harder for myself than it was. It's just that our book goes directly from println to JOptionPane & then to adding integers, but not how to declare character variables. What you suggested worked!
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
...yet another victim of the [expletive deleted] instructors and books that try to force Swing down a brand new programmer's throat... I do not like this trend.
Don't be discouraged. Java programming is easy. If your book isn't perfect (and what book could be?), then hit the internet for volumes of free Java learning information (like this great site!).
Good Luck.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You might want to pick up Ivor Horton's, "Beginning Java 2". I think you will find it very helpful. I use it for the course I teach.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Very funny. I allegedly won a copy of that book almost two months ago. Two of the other winners did receive their copies. I have not. I did almost go and buy it, but then became bitter at the thought.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Declaring strings
 
Similar Threads
Syntax check (losing hair now)...
Displaying a Single Record with a Comma Separated Column from Multiple Records
Escape characters in JDBC (single quote/apostrophe)
Question about enums and enhanced for
Need help with HashMap object mapping-- type mismatch how to fix?