Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Declaring strings

 
Julie Montoya
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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???
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
Julie Montoya
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Julie Montoya
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...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
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic