Two Laptop Bag*
The moose likes Beginning Java and the fly likes Just a bit of advice on my first program. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Just a bit of advice on my first program." Watch "Just a bit of advice on my first program." New topic
Author

Just a bit of advice on my first program.

Michael Humphreys
Greenhorn

Joined: Dec 22, 2010
Posts: 23

Hi All, Well, I have been studying Java for just over a month and I have almost finished my first program. But as you see I am stuck. Below is a copy of the code for a program I wrote MANY years ago in Tandy Basic, written in Java. I don't understand why my System.out.println call won't work. A word of why would help. I don't want you to fix it just let me know how to fix it myself. Any help would be great. Here is the code:

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

Welcome to JavaRanch!

The println() method takes just one argument. In Java, you can create longer strings out of shorter pieces using the "+" operator, so

"Number of Hens = " + hens

assembles the two pieces "Number of Hens =" and the contents of the variable 'hens' together into one long String. Then you can pass that String to println():

System.out.println("Number Of Hens = " + hens);


[Jess in Action][AskingGoodQuestions]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14117
    
  16

Welcome to JavaRanch. Please UseCodeTags when you post source code.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Michael Humphreys
Greenhorn

Joined: Dec 22, 2010
Posts: 23

Thank you for the replies. I do understand about the code formating just didn't know how to do it thanks.

Well, I finished the changes and ran the program and IT WORKED! Thanks again for the pointers.

Here is the repaired code so ppl can see what i did.


fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

Michael Humphreys wrote:I don't understand why my System.out.println call won't work.

Glad you were able to get your code to work.

Another tip for posts around here....generally, saying "X doesn't work" doesn't help anyone understand your problem. It could mean anything from 'javac is not a recognized program or executable" to classpath issues to syntax errors to logic errors to any of about a billion other things.

Your job, when posting here, is to make it as easy as possible for folks to help you. If you get a syntax error when compiling, post the exact and complete text of that error. If the results are different than what you expect when you run it, tell us what you got AND what you expected.

people here LOVE to help others. But, if it comes to a choice between helping someone who has made it easy to help them and someone who made it hard...well...you can guess which most folks would choose.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Kevin Workman
Ranch Hand

Joined: Sep 28, 2010
Posts: 151
The OP crossposted this topic here.

OP- Please BeForthrightWhenCrossPostingToOtherSites. I feel like I wasted my time on the other forum simply repeating help you already received, and will probably not be helping you in the future.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38510
    
  23
Agree with Kevin Workman.

But are you aware of the PrintStream#printf(java.lang.String,%20java.lang.Object...) method, or the Formatter class. They will allow you to format output. System.out is a PrintStream, so you can write System.out.printf( . . . ).
Michael Humphreys
Greenhorn

Joined: Dec 22, 2010
Posts: 23

Thank you for all of your responses. I have assimilated your suggestions and will take action to implement same in a rapid fashion. As for Campbell Ritchie and Kevin Workman I am sorry that I stepped on your toes so to speak. I was not aware of the requirement and will surely not crosspost in the future, but do you not think it just a bit harsh that after one infraction and the poster is told he will receive no more help? Thank you all for your help
allen1952
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

There's no official policy about not helping crossposters; it's just that Kevin feels his effort helping you on another site was wasted, and won't personally want to help you again. A lot of people will feel that way.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30392
    
150

Michael,
It's not even that cross posting on another site is bad. The idea is to provide a link to the cross post in each place. That way someone can see if your issue has been solved before posting.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38510
    
  23
Michael Humphreys wrote: . . . I am sorry that I stepped on your toes so to speak. . . .
Sorry for not replying earlier. Apologies accepted.
I won't go so far as not to help in future, myself.
Michael Humphreys
Greenhorn

Joined: Dec 22, 2010
Posts: 23

Campbell Ritchie wrote:
Michael Humphreys wrote: . . . I am sorry that I stepped on your toes so to speak. . . .
Sorry for not replying earlier. Apologies accepted.
I won't go so far as not to help in future, myself.


Thank you Campbell, I do have a better understanding of what cross-posting is and will avoid it at all cost (smiles). Thank you all for your responses.
Michael
 
 
subject: Just a bit of advice on my first program.