Results 1 to 14 of 14
Thread: Do not know how to solve this
- 05-30-2011, 04:47 PM #1
Member
- Join Date
- May 2011
- Posts
- 29
- Rep Power
- 0
Do not know how to solve this
Hi I'm a new student of java programming. I ran this code, there's a problem but I do not know how to solve it. Please help.
Java Code:public class Q3 { double length=5, width=8, height=9, radius=6; public static double volume(double length, double width, double height) { double box= length * width * height; return box; } public static void main(String[] args){ System.out.println("The volume of rectangular box is "+ volume()); } }
- 05-30-2011, 04:53 PM #2
Pass the parameters to your volume method.
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 05-30-2011, 05:07 PM #3
Member
- Join Date
- May 2011
- Posts
- 29
- Rep Power
- 0
Hi I've made amendments to it and it works, thanks Goldest!
System.out.println("The volume of rectangular box is "+ volume(5,8,9));
Initially I put the parameters as
System.out.println("The volume of rectangular box is "+ volume(length,width,height));
Question, is there a way I can pass English words as parameters instead of numbers?
- 05-30-2011, 05:13 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Sure you can as long as you define those English words to be visible variables; here you define three local variables in your main( ... ) method:
Next you can call your method as:Java Code:double length= 5.0; double width= 8.0; double height= 9.0;
kind regards,Java Code:System.out.println("The volume of rectangular box is "+ volume(length,width,height));
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-30-2011, 05:13 PM #5
- 05-30-2011, 05:15 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 05-30-2011, 05:19 PM #7
Member
- Join Date
- May 2011
- Posts
- 29
- Rep Power
- 0
Goldest and Jos, when I tried this, it has errors:
What does this mean?Java Code:System.out.println("The volume of rectangular box is "+ volume(length, width, height)); ^ 3 errorsLast edited by jaylimix; 05-30-2011 at 05:22 PM.
- 05-30-2011, 05:21 PM #8
Java Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 05-30-2011, 05:23 PM #9
Member
- Join Date
- May 2011
- Posts
- 29
- Rep Power
- 0
- 05-30-2011, 05:26 PM #10
Member
- Join Date
- May 2011
- Posts
- 29
- Rep Power
- 0
Ya I manage to make it work by adding a static in front of the variable. It's just guessing for me based on the error.
- 05-30-2011, 05:27 PM #11
- 05-30-2011, 05:42 PM #12
Aahh, well thats another way.
Considering that you are new to Java, I would strongly suggest you to have a look at the common java errors here : Top Ten Errors Java Programmers Make.
Hope that would be beneficial for you.-.gif)
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
- 05-30-2011, 06:04 PM #13
Member
- Join Date
- May 2011
- Posts
- 29
- Rep Power
- 0
Ya I got what you guys mean about the define as local variable
Thanks for the help! Thanks for link too.
- 05-31-2011, 11:42 AM #14
Similar Threads
-
Please help me to solve it(jsp)
By srengvichet in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 08-15-2010, 03:52 PM -
PLS PLS PLS PLS solve this
By unagie in forum New To JavaReplies: 10Last Post: 07-11-2009, 09:10 PM -
Plz solve this....
By theone3nu in forum Java 2DReplies: 3Last Post: 01-08-2009, 05:01 PM -
Plz solve this....
By theone3nu in forum New To JavaReplies: 9Last Post: 12-23-2008, 09:42 AM


LinkBack URL
About LinkBacks
Reply With Quote

.gif)

Bookmarks