Results 1 to 6 of 6

Thread: Java method

  1. #1
    javasm is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default Java method

    Hi all,
    I am having a problem with running the following code.
    I am trying to write a program that captures and prints square root of four numbers. I can't continue because my method shows an error which I can't find.

    Thanks for any help in advance.


    package javaapplication9;




    public class square {

    public double add(double a,double b,double c,double d){

    c=a*a;
    d=b*b;
    double x=Math.sqrt(c+d);
    double y=Math.sqrt(c-d);
    double max=x+y;

    System.out.println("X is:" + add(a,b,c,d));

    }


    public static void main(String[] args) {





    }

    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,771
    Blog Entries
    7
    Rep Power
    21

    Default Re: Java method

    What's the error?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    javasm is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default Re: Java method

    It says "Missing return statement".

    I tried putting a return statement, and still, nothing.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,771
    Blog Entries
    7
    Rep Power
    21

    Default Re: Java method

    Your add( ... ) method claims to return a value of type double, but it doesn't return such value anywhere. Pay special atterntion: your method calls itself recursively in the System.out.println( ... ) statement.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    javasm is offline Member
    Join Date
    Mar 2012
    Posts
    3
    Rep Power
    0

    Default Re: Java method

    Should I remove the System.out.pritnln statement and use return statement alone?

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,771
    Blog Entries
    7
    Rep Power
    21

    Default Re: Java method

    Quote Originally Posted by javasm View Post
    Should I remove the System.out.pritnln statement and use return statement alone?
    I don't know your intentions but as it is now, your method calls itself in the System.out.println( ... ) statement which is ABT (A Bad Thing (tm)).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Need a way to run a method in java at a certain time
    By ShinTec in forum Advanced Java
    Replies: 4
    Last Post: 08-19-2011, 01:31 PM
  2. Creating a second method in java
    By Teclis in forum New To Java
    Replies: 3
    Last Post: 04-09-2011, 06:49 PM
  3. Replies: 3
    Last Post: 02-09-2010, 06:22 AM
  4. Post Method in java.net
    By freddieMaize in forum Advanced Java
    Replies: 2
    Last Post: 02-23-2009, 03:59 AM
  5. Call Java Method
    By hussainzim in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 05-15-2008, 08:22 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
  •