 | |
10-06-2003, 04:49 PM
|
#1 (permalink)
| | Registered User
Join Date: Jul 2002 Location: Texas A&M
Posts: 438
| » 
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
|
| |
10-06-2003, 05:27 PM
|
#2 (permalink)
| | Registered User
Join Date: Oct 2001 Location: ~/
Posts: 2,567
|
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.
|
| |
10-06-2003, 05:45 PM
|
#3 (permalink)
| | Registered User
Join Date: Jul 2002 Location: Texas A&M
Posts: 438
|
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....
__________________
The Terk
|
| |
10-06-2003, 05:52 PM
|
#4 (permalink)
| | Registered User
Join Date: Oct 2001 Location: ~/
Posts: 2,567
|
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.
|
| |
10-06-2003, 10:24 PM
|
#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.
|
| |
10-06-2003, 11:08 PM
|
#6 (permalink)
| | Registered User
Join Date: Oct 2001 Location: ~/
Posts: 2,567
|
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
|
| |
10-07-2003, 09:30 AM
|
#7 (permalink)
| | Registered User
Join Date: Oct 2001
Posts: 691
|
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
|
| |
10-07-2003, 01:36 PM
|
#8 (permalink)
| | Registered User
Join Date: Jul 2002 Location: Texas A&M
Posts: 438
| 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
__________________
The Terk
|
| |
10-07-2003, 03:20 PM
|
#9 (permalink)
| | Registered User
Join Date: Oct 2001 Location: ~/
Posts: 2,567
|
We were refering to arrays declared in main and accessed in other methods.
|
| |
10-07-2003, 10:06 PM
|
#10 (permalink)
| | Registered User
Join Date: Jul 2002 Location: Texas A&M
Posts: 438
| 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);
}
__________________
The Terk
|
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions  | | | | | Recent Discussions  | | | | | |