Results 1 to 10 of 10
  1. #1
    KonchShell is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default System.out.println not printing, weird output

    Hello everyone I am VERY new to java and have written a simple class to hold the x-coord, y-coord and radius of a circle. So far I have written class, constructor, etc. up until a print of the current x coordinate of the circle.

    here is the code:
    [Java] mejava2 - Pastebin.com

    this is the output, that i am receiving after building and running. PS I am using Netbeans.
    javaoutputme - Pastebin.com

    Can anyone explain why it is not just printing the x integer, and what all of the stuff in the output means.

    Thanks.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Recommended reading: How to ask questions the smart way

    If the code's too long to post here, it's too much code to expect help on a forum.

    And if you're really VERY new to Java, start here:
    Trail: Getting Started (The Java™ Tutorials)

    db

  3. #3
    FlyNn is offline Senior Member
    Join Date
    Feb 2010
    Posts
    128
    Rep Power
    0

    Default

    after creating your object MyCircle, when are you calling method printx?
    Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

  4. #4
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    I'm not following the external link but if you're having trouble printing your circle's current co-ordinates, i'm just thinking a common mistake for new java programmers would be a type mismatch. The output has to be a String, not a number (Int, Double, etc)

    So if your co-ordinates are a number, convert it to a String before you print it, or use the java Formatter e.g.

    Java Code:
    int circleX = myCircle.getX();
    System.out.printf("The current X coordinate is: %d",circleX);

  5. #5
    KonchShell is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by Darryl.Burke View Post
    Recommended reading: How to ask questions the smart way

    If the code's too long to post here, it's too much code to expect help on a forum.

    And if you're really VERY new to Java, start here:
    Trail: Getting Started (The Java™ Tutorials)

    db
    Thank you for your reply, I have been following the oracle tutorials, that is how I am learning. I have reached the point of declaring classes and whatnot, so I was hoping someone could assist me with the printing issue.

    Quote Originally Posted by ozzyman
    So if your co-ordinates are a number, convert it to a String before you print it, or use the java Formatter e.g.

    Code:
    int circleX = myCircle.getX();
    System.out.printf("The current X coordinate is: %d",circleX);
    Ozzyman, thank you for your help, are you suggesting I create a variable integer, circleX; or that I place "%d" in my output code? I am confused because you told me to create a string, while circleX would be an integer, but I am also unsure because I don't know what %d does.

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Quote Originally Posted by KonchShell View Post
    this is the output, that i am receiving after building and running.
    I don't see anywhere the output of running the code. All you have done is to build the project.

  7. #7
    KonchShell is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    Junky, the output im getting in the Netbeans output window after running is on the page the link leads to, below the text you quoted.

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Yes I followed the link and the last line is "BUILD SUCCESSFUL (total time: 0 seconds)". That is building the project not running it.

  9. #9
    KonchShell is offline Member
    Join Date
    Mar 2011
    Posts
    4
    Rep Power
    0

    Default

    Yes it says build successful: that happens when I click run. I am not sure what else to click, I figured "run main project" would run my project. I posted this topic because there is no output of the integer of the x coordinate of the circle, which should output "3".

  10. #10
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    are you suggesting I create a variable integer, circleX; or that I place "%d" in my output code?
    notice System.out.printf is not the same as System.out.print, the 'f' stands for formatter.
    there is another way to write this:
    Java Code:
    String myString = String.format("The number is %d and it is output with a formatter",myNumber);
    System.out.println(myString);
    The java formatter replaces the %d with an integer. 'd' stands for decimal number. So if myCircle.getX() = 3, the output for this code:
    Java Code:
    int circleX = myCircle.getX();
    System.out.printf("The current X coordinate is: %d",circleX);
    Would be this:
    The current X coordinate is: 3

    You can learn about the Java Formatter here:
    http://download.oracle.com/javase/tu...mat/index.html

Similar Threads

  1. Save the output from system.out.println into a file
    By Iskatel in forum Advanced Java
    Replies: 5
    Last Post: 10-05-2010, 02:52 PM
  2. System.out.println
    By JohnDoe in forum New To Java
    Replies: 1
    Last Post: 09-05-2010, 10:14 AM
  3. Println VS system.out.println
    By ccie007 in forum New To Java
    Replies: 2
    Last Post: 05-20-2010, 08:52 AM
  4. difference between system.out.println() & out.println()
    By wickedrahul9 in forum Advanced Java
    Replies: 5
    Last Post: 10-18-2008, 11:06 PM
  5. System.out.println
    By sunjavaboy in forum Advanced Java
    Replies: 3
    Last Post: 03-22-2008, 01:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •