Results 1 to 6 of 6
Thread: Quick help
- 01-06-2010, 02:45 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 3
- Rep Power
- 0
Quick help
I spent some time on the sun website reading about classes, but I can't seem to find what I'm looking for.
I got a quick introduction to classes when I used Visual Basic 6 for about a week. I'd like to use classes in Java the same way. I'm trying to do something like this:
d=5;
for (b=.25; b<10; b=b+1/4) {
findangle(b); }
System.out.println(angle) // which is shown just below
//then somewhere (this is where I'm lost)
class findangle(b as double) {
angle=arccos(d/(2*b)); }
Do I need to write class "findangle" in a separate .java file in the same folder? How would that class look, would it have a main? Is there way to have it in the same file? (I guess it's like defining a "Math." function, but I'm still not 100% how they work.)
It seems like the one line "angle=....." could just as easily be put into the "for" statement, but I have so many little statements like this the code gets jumbled very quickly. Is there a better way of organizing the program than using classes?
Thanks,
James
- 01-06-2010, 03:47 AM #2
Senior Member
- Join Date
- Oct 2009
- Location
- California,US
- Posts
- 201
- Rep Power
- 4
ok If i am current in interepreting your question.
are you asking wether the for loop ? and the findangle method to be in the same class.?
This is not the correct way of writing the java class.
heres crude replica of your code.Java Code:d=5; for (b=.25; b<10; b=b+1/4) { findangle(b); } System.out.println(angle) // which is shown just below //then somewhere (this is where I'm lost) class findangle(b as double) { angle=arccos(d/(2*b)); }
Java Code:class structure { private double angle; void findangle(double b) { angle=arccos(d/(2*b)); // use math library. } public void calculation() { int d=5; for (b=.25; b<10; b=b+1/4) { findangle(b); } System.out.println(angle) // which is shown just below } }
- 01-06-2010, 07:57 PM #3
Member
- Join Date
- Jan 2010
- Posts
- 3
- Rep Power
- 0
Sorry, I think what I was trying to ask is how can I write a quick subroutine in Java?
-
You just need to call the static method in the Math class that finds that inverse of the cosine, I believe that it's Math.acos(double angleInRadians). But more importantly, you should go through a Java book or the Sun tutorial as you're making several very basic errors here that will be corrected with diligent study.
- 01-06-2010, 10:29 PM #5
Member
- Join Date
- Jan 2010
- Posts
- 3
- Rep Power
- 0
That was just kind of an example. I've been leafing through a book but it only talks about subroutines in the context of objects, which I'm not interested in.
-
Similar Threads
-
Quick and Easy Job.
By Scottyb in forum Jobs OfferedReplies: 3Last Post: 08-11-2009, 03:48 PM -
Hello everyone! quick question.
By irishhokie in forum New To JavaReplies: 5Last Post: 04-03-2009, 04:13 AM -
Quick reg. expression help
By RR_QQ in forum New To JavaReplies: 4Last Post: 02-10-2009, 07:51 PM -
Need help quick!
By Manikyr in forum New To JavaReplies: 11Last Post: 01-28-2009, 04:08 AM -
One last quick question
By jigglywiggly in forum New To JavaReplies: 7Last Post: 01-26-2009, 08:53 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks