Results 1 to 6 of 6
Thread: Java method
- 03-16-2012, 12:53 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
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) {
}
}
- 03-16-2012, 01:30 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
Re: Java method
What's the error?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-16-2012, 01:32 PM #3
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
Re: Java method
It says "Missing return statement".
I tried putting a return statement, and still, nothing.
- 03-16-2012, 01:38 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-16-2012, 01:40 PM #5
Member
- Join Date
- Mar 2012
- Posts
- 3
- Rep Power
- 0
Re: Java method
Should I remove the System.out.pritnln statement and use return statement alone?
- 03-16-2012, 01:42 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,399
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Need a way to run a method in java at a certain time
By ShinTec in forum Advanced JavaReplies: 4Last Post: 08-19-2011, 12:31 PM -
Creating a second method in java
By Teclis in forum New To JavaReplies: 3Last Post: 04-09-2011, 05:49 PM -
Java class HashIt with a static recursive method and a static iterative method
By kezkez in forum New To JavaReplies: 3Last Post: 02-09-2010, 05:22 AM -
Post Method in java.net
By freddieMaize in forum Advanced JavaReplies: 2Last Post: 02-23-2009, 02:59 AM -
Call Java Method
By hussainzim in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 05-15-2008, 07:22 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks