Archive:Java/Programming tips: Difference between revisions
Appearance
wikademia>Cremisis13 New page: =When to use methods= =About Arrays= Arrays should be used for variables that have something to do with each other. Basically, arrays are a list of variables, and arrays are a variable the... |
wikademia>Cremisis13 |
||
| Line 21: | Line 21: | ||
</pre> | </pre> | ||
'''Note''': Do NOT use arrays when the members have nothing to do with each other. This causes messy code! | '''Note''': Do NOT use arrays when the members have nothing to do with each other. This causes messy code! | ||
=Basic Tips for Improving Code | |||
Revision as of 23:05, 26 November 2006
When to use methods
About Arrays
Arrays should be used for variables that have something to do with each other. Basically, arrays are a list of variables, and arrays are a variable themselves. Here is how to make an array
[class][] [variable-name]; //Or... int[] myInts;
To specify the length of an array:
myInts=new int[LENGTH]; //Put into one statement int[] myInts = new int[LENGTH];
LENGTH = array size. It is simply how many items are in the array.
You need to initialize each part of the array. To "access" the members of the array:
myInts[2]==5; int temp = myInts[3];
Note: Do NOT use arrays when the members have nothing to do with each other. This causes messy code! =Basic Tips for Improving Code