Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: easy question for a pro

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default easy question for a pro

    I am a college student just starting out with java and I am working with pretty easy stuff here (I guess, lol), but im just trying to learn one bit at a time. I am just displaying my values in different ways and I can't seem to get my values to display one at time on new lines. I dont know why the \n isnt compiling. The part i am having trouble with has the "Not Working" tag in the code.

    [highlight=Java]
    //Trying to figure out how to use /n
    public class Test
    {
    public static void main(String[] args)
    {
    int gold= 5;
    int silver= 3;
    int bronze= 1;

    //Stacked titles
    System.out.println(" gold\n silver\n bronze");
    //Values stacked (not working)
    System.out.print (gold\n silver\n bronze);
    //Values side by side
    System.out.println( gold + " " + silver + " " + bronze);
    //Values added together
    System.out.println(gold + silver + bronze);
    }
    }


  2. #2
    Junior Member BlackStones's Avatar
    Join Date
    Feb 2014
    Posts
    15
    My Mood
    Fine
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: easy question for a pro

    Try this

    //Values stacked (now actually working)
            System.out.println(gold +  "\n" + silver + "\n" + bronze + "\n");

  3. The Following User Says Thank You to BlackStones For This Useful Post:

    meangreen2003 (February 16th, 2014)

  4. #3
    Junior Member
    Join Date
    Feb 2014
    Posts
    11
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: easy question for a pro

    I would like to see the values stacked on different lines and that just re-does what my first statement did. Thank you for taking a look, I really do appreciate it.
    I would like to see the following output:

    Welcome to DrJava. Working directory is C:\Users\Chad
    > run Test
    gold
    silver
    bronze
    5
    3
    1
    5 3 1
    9
    >

    --- Update ---

    I am so sorry you are right that works great. Thank you

    --- Update ---

    Seems weird though because I thought that "\n" should have displayed \n. Thank You again BlackStones.

Similar Threads

  1. Very easy question about output.
    By ma5sacre in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 11th, 2014, 09:12 AM
  2. An easy question
    By KAJLogic in forum Java Theory & Questions
    Replies: 5
    Last Post: December 1st, 2013, 03:55 AM
  3. How do I get this to work? Easy question, I'm just hopeless at it!
    By akmi5 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 1st, 2012, 01:31 PM
  4. "Pro Android 3" Book Example Code Question
    By mike duron in forum Android Development
    Replies: 1
    Last Post: April 8th, 2012, 12:43 PM
  5. Easy array question
    By surfbumb in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 3rd, 2011, 08:44 PM