home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

new at java, cant make methods

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1717
Discussions: 200,924, Posts: 2,379,121, Members: 246,290
Old October 6th, 2003, 07:49 PM   Digg it!   #1 (permalink)
Senior Member
 
The Terk's Avatar
 
Join Date: Jul 2002
Location: Texas A&M
Posts: 611
Send a message via AIM to The Terk
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
The Terk is offline   Reply With Quote
Old October 6th, 2003, 08:27 PM     #2 (permalink)
dword to your moms
 
krohnjw's Avatar
 
Join Date: Oct 2001
Location: ~/
Posts: 3,195
Send a message via AIM to krohnjw
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.
krohnjw is offline   Reply With Quote
Old October 6th, 2003, 08:45 PM     #3 (permalink)
Senior Member
 
The Terk's Avatar
 
Join Date: Jul 2002
Location: Texas A&M
Posts: 611
Send a message via AIM to The Terk
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 is offline   Reply With Quote
Old October 6th, 2003, 08:52 PM     #4 (permalink)
dword to your moms
 
krohnjw's Avatar
 
Join Date: Oct 2001
Location: ~/
Posts: 3,195
Send a message via AIM to krohnjw
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.
krohnjw is offline   Reply With Quote
Old 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.
pedantic is offline   Reply With Quote
Old October 7th, 2003, 02:08 AM     #6 (permalink)
dword to your moms
 
krohnjw's Avatar
 
Join Date: Oct 2001
Location: ~/
Posts: 3,195
Send a message via AIM to krohnjw
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
krohnjw is offline   Reply With Quote
Old October 7th, 2003, 12:30 PM     #7 (permalink)
Senior Member
 
Join Date: Oct 2001
Posts: 881
Send a message via AIM to 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
zskillz is offline   Reply With Quote
Old October 7th, 2003, 04:36 PM     #8 (permalink)
Senior Member
 
The Terk's Avatar
 
Join Date: Jul 2002
Location: Texas A&M
Posts: 611
Send a message via AIM to The Terk
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 is offline   Reply With Quote
Old October 7th, 2003, 06:20 PM     #9 (permalink)
dword to your moms
 
krohnjw's Avatar
 
Join Date: Oct 2001
Location: ~/
Posts: 3,195
Send a message via AIM to krohnjw
We were refering to arrays declared in main and accessed in other methods.
krohnjw is offline   Reply With Quote
Old October 8th, 2003, 01:06 AM     #10 (permalink)
Senior Member
 
The Terk's Avatar
 
Join Date: Jul 2002
Location: Texas A&M
Posts: 611
Send a message via AIM to The Terk
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 is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2863)
Obama the Muslim (14)
California Passes Anti-Flat-HDTV Le.. (39)
Is the PSU I received dead? (10)
windows vista security holes (9)
Foreign voltage (10)
Install XP pro and a Vista laptop ?.. (10)
HIS HD5770 graphic card question (15)
Print spooler problem (13)
Dept. of HS: NSA 'Helped' Develop V.. (15)
A good PSU? (10)
New Computer wont recognize XP disc (7)
Ideal cheap graph card for PC-Gamin.. (15)
EVGA 9800 gtx help with finding a g.. (8)
Recent Discussions
Have you switched yet? (84)
Install XP pro and a Vista laptop ?? (10)
Wireless Router+Cable Modems and Much.. (0)
Optical Audio A-B Switch (1)
windows vista security holes (9)
Fire in DVD (0)
radeon x850xt platinum & shader 3 (2)
The NTDVM CPU has encountered an ille.. (24)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (34)
Wireless speakers for PC? (11)
Print spooler problem (13)
Help getting around port 80 for camer.. (2)
Display shows 3x5 inch in middle of s.. (3)
monitor will not turn on at all, (1)
World's largest Monopoly Game using G.. (331)
Foreign voltage (10)
FiOS modem/router interfering with ne.. (7)
Browsers wont load websites (2)
Virus Doctor Popup? (1)
Dept. of HS: NSA 'Helped' Develop Vis.. (15)
EVGA 9800 gtx help with finding a goo.. (8)
Modern Warfare For the PC (32)
Problem with speed step/turbo boost? (1)
Modern Warfare 2: Who Bought It? (61)
SIS 740 and Widescreen (8)


All times are GMT -4. The time now is 12:07 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28