• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using methods  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...I am trying to do practice problems and I am having a lot of trouble. I am attempting to use method and have it print out EXACTLY like this:

Print all characters between a and w
a b c d e f g h i j
k l m n o p q s t
v w

 
Ranch Hand
Posts: 68
3
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Cece. ^_^

You want the method to print out exactly as you have written it? Inside the method you can just use an output stream that prints exactly as you see it there. So, am I not understanding your issue?
 
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To illustrate what Skye said, the following program meets your requirements, but is it really what the practice problem states?

 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope.

 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl, when someone asks you "Say hello, Darryl!" then you respond with "hello, Darryl!"?
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:Darryl, when someone asks you "Say hello, Darryl!" then you respond with "hello, Darryl!"?


I went with the spec
Cece Nickson wrote:... have it print out EXACTLY like this:

Print all characters between a and w
...
 
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I must admit I agree with Darryl
OP stressed exact math of lines below is needed using CAPITAL LETTERS.

Jesper de Jong wrote:Darryl, when someone asks you "Say hello, Darryl!" then you respond with "hello, Darryl!"?

Your example is wrong. It should be: "Darryl, say those EXACT words: »hello, Darryl«".
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah..but you are both wrong.


You had extra spaces on the end of each line.

 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going to point this out but this would be too nitpicky so I resigned
 
Cece Nickson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did it that way and my instructor says I should use a for loop instead and have another method inside the class. I thought I understood what he meant but I am lost.

The problem says" The printChars() method will print out on the console all the characters between c1 and c2, 10 per line. Your main() method will call the printChars()
method passing 2 characters.

So far I have:


P.S. I am taking a beginning Java class and this is my 3rd week so any advice would be helpful.

THANKS IN ADVANCE FOR ALL YOUR HELP!!!
 
Knute Snortum
Sheriff
Posts: 4289
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know that a char can also be used like a number? Does that help? (We'll try to give you hints rather than just tell you the answer.)
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My advice would be to StopCoding (<---click that).

You seem to be writing code without knowing what you want to do. The main thing that will do is frustrate you.

So stop. Think about the problem, in English (or any other natural language). Write out the steps as if you were instructing a small child what to do.

Knute has given you a good hint, once you do the above. the character 'a' is represented by the number 97, 'b' by 98, etc. You can see that if you look at an Ascii Table.
 
Cece Nickson
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys for your advice! I am still lost and I feel like this should be simple compared to whats to come! I attempted to take Fred's advice and write it down but to my eyes, when I write it, it looks exactly like what should printed out. For these first few weeks, I have worked backward from the code to the problem and that has helped me understand it better.

Is there is other suggestions you would have to learn this language??
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you written out? I would expect something like this:

  • You will be given two characters. They will be in alphabetical order, but no necessarily consecutive. For example, you may get 'a' and 'w'. or you may get 'n' and 'p'.
  • Print the letters of the alphabet, starting with the first character you were given.
  • after each character, print a space.
  • After you have printed 10 characters on a single line, move to the next line.
  • Continue printing characters and spaced, 10 per line, until you have printed the second character you were given, then quit.


  • You'll notice how i have not really ever used a "java" word here. I'm just trying to talk to someone, explaining what they need to do.
    This should always be your first step, before you write one word of java code.
     
    Marshal
    Posts: 56607
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Do you actually want to print a new line after ten characters?
     
    Cece Nickson
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    No, I don't need to print a line. I need to use 2 methods to print the display...
     
    Ranch Foreman
    Posts: 3071
    37
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Cece Nickson wrote:No, I don't need to print a line. I need to use 2 methods to print the display...


    Well, according to the requirements you posted above you do:
    "10 per line".

    ETA: But, and this is a big "but", don't worry about the new lines. Never try and do all the things in one go.
    That way lies madness.
    Using fred's description as a basis, expanded if you feel it needs more detail, take each step at a time and ensure it works.
    So, write code that takes two characters. Print them out to make sure that works (that would be the first sentence in your output).

    So now step 1 works.

    Now move on and print out the letters from the first character to the last.
    Does that work? (Forget spaces and new lines).

    And so on.

    All software dev is like this.
    Look at the requirements.
    Jot down how you think (in English) the flow should work.
    Code each step and ensure that step works before moving on to the next one. No sense building on broken foundations.


    ...and my edit is longer than my original post!
     
    Campbell Ritchie
    Marshal
    Posts: 56607
    172
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Do you really need two methods? I would write it with one method
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!