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 4 of 4

Thread: wrong code?

  1. #1
    Junior Member
    Join Date
    Nov 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default wrong code?

    Hi!

    I have the following code, but when i run it the output get the circumference to 0.0.
    Would appreciate any help! Thanks!

    private void doButton1ActionPerformed(java.awt.event.ActionEven t evt) {

    output.append("the circumference is " + circumference);
    }

    public double circumference(double radius) {
    final double PI = 3.1415;
    radius = Double.parseDouble(input1.getText());
    circumference= 2*PI*radius;
    return circumference;

    }

    double circumference;

    method_PI.jpg

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,309
    Thanks
    53
    Thanked 2,391 Times in 2,345 Posts

    Default Re: wrong code?

    Have you tried debugging the code to see that is it being executed as expected and that expected values are computed.
    One way to do that is add print statements that print the value of all the variables so you can see if the code is executed and if it is computing the correct values.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: wrong code?

    I tried to do that. But i'm still learning i'm in not sure how to interpret the results.
    Thanks for the reply!

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,309
    Thanks
    53
    Thanked 2,391 Times in 2,345 Posts

    Default Re: wrong code?

    not sure how to interpret the results.
    Copy what is printed and post it here if you need help.

    Be sure all print statements print unique values so the source of the values printed is known:
    System.out.println("1variable="+ variable);
     
    ...
     
    System.out.println("2variable="+ variable);
    Note the 1 and 2 make the print outs unique.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. What is wrong with my code?
    By iMiTzi in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 5th, 2014, 11:45 AM
  2. [SOLVED] can anyone help me what is wrong with my code?
    By marc172 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 22nd, 2013, 08:53 PM
  3. what's wrong with this code
    By gcsekhar in forum Java Networking
    Replies: 5
    Last Post: July 21st, 2011, 06:01 AM
  4. What is Wrong with my code
    By xew123 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 8th, 2011, 03:59 AM
  5. What's wrong with my code ?
    By mithani in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 5th, 2010, 08:57 AM