new at java, cant make methods  | | |
October 6th, 2003, 07:49 PM
|
#1 (permalink)
| | Senior Member
Join Date: Jul 2002 Location: Texas A&M
Posts: 611
| new at java, cant make methods
ok, i have programmed a lil bit in c++ and i cant seem to make methods to solve my problems... such as create an array that has a user defined size and user defined values, then find the max, min, most frequent value, and etc... i can do it all in one function, but splitting it into methods is completely out of my mind.... someone please ease the pain!
*note- all these different functions are supposed to be methods
__________________
The Terk
|
| |
October 6th, 2003, 08:27 PM
|
#2 (permalink)
| | dword to your moms
Join Date: Oct 2001 Location: ~/
Posts: 3,195
|
method == function.
When using the array in java it does not need to be returned or used as a reference variable to be altered. Any alterations to the array are permanent.
It sounds like you are suposed to write a bunch of functions, with the first being setting the array.
would you care to elaborate where you are having problems here? From what I am reading you are just writing a bunch of functions (methods) like findMin, findMax, mostFrequent, etc. |
| |
October 6th, 2003, 08:45 PM
|
#3 (permalink)
| | Senior Member
Join Date: Jul 2002 Location: Texas A&M
Posts: 611
|
ok, how do i access the array through the other methods? i make a new area in the newArray() function, i ask the person how big it is using JOptionPane, parseInt it into the size, so array[size] is the new size? for loop more JOptionPanes to get the values, etc etc... how can i access that array if it is part of a different method? or does that all go in the main? srry for the nub-ness of such questions.... |
| |
October 6th, 2003, 08:52 PM
|
#4 (permalink)
| | dword to your moms
Join Date: Oct 2001 Location: ~/
Posts: 3,195
|
It will all be in main memory. For arrays you dont have to worry about scope. For returning the max, min, etc, you will need to use return statements as those only exists inside of the method. |
| |
October 7th, 2003, 01:24 AM
|
#5 (permalink)
| | Banned
Join Date: Sep 2003
Posts: 35
| Quote: |
For arrays you dont have to worry about scope.
| yes, you do. though method==function.
java scope aware.
C?C++ memory location aware(hi pointers).
both OO. |
| |
October 7th, 2003, 02:08 AM
|
#6 (permalink)
| | dword to your moms
Join Date: Oct 2001 Location: ~/
Posts: 3,195
|
In java you do not need to worry about the scope of the array inside of a method, ie it will not go out of scope when it leaves the method. Note that I did not say this applied to any other classes.
Also note we were ONLY working in Java here. We talked via AIM and got things sorted out |
| |
October 7th, 2003, 12:30 PM
|
#7 (permalink)
| | Senior Member
Join Date: Oct 2001
Posts: 881
|
well crapola!... now I'm confused.
I sure thought that if I declared and instantiated an array within method "dec_array", that once I moved outside of that method, I could not access it with other methods....
clarification please...?
-Z |
| |
October 7th, 2003, 04:36 PM
|
#8 (permalink)
| | Senior Member
Join Date: Jul 2002 Location: Texas A&M
Posts: 611
| Quote: Originally posted by zskillz well crapola!... now I'm confused.
I sure thought that if I declared and instantiated an array within method "dec_array", that once I moved outside of that method, I could not access it with other methods....
clarification please...?
-Z | as long as that method has a return for that array, then the main method will have that reference for the rest of ur functions to call from |
| |
October 7th, 2003, 06:20 PM
|
#9 (permalink)
| | dword to your moms
Join Date: Oct 2001 Location: ~/
Posts: 3,195
|
We were refering to arrays declared in main and accessed in other methods. |
| |
October 8th, 2003, 01:06 AM
|
#10 (permalink)
| | Senior Member
Join Date: Jul 2002 Location: Texas A&M
Posts: 611
| Quote: Originally posted by krohnjw We were refering to arrays declared in main and accessed in other methods. | heres a function for ya:
public static void main(String[] args)
{
I am nub!;
System.exit(0);
} |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |