Java Reference
In-Depth Information
EXAMPLES (OF ARRAY PARAMETERS)
public class AClass
{
public static void listChars( char [] a)
{
int i;
for (i = 0; i < a.length; i++)
System.out.println(a[i] + " ");
}
public static void zeroAll( int [] anArray)
{
int i;
for (i = 0; i < anArray.length; i++)
anArray[i] = 0;
}
...
}
EXAMPLES (OF ARRAY ARGUMENTS)
char [] c = new char [10];
int [] a = new int [10];
int [] b = new int [20];
Note that arrays a and b have
different lengths. Also note that
no square brackets are used with
array arguments.
< Some code to fill the arrays goes here. >
AClass.listChars(c);
AClass.zeroAll(a);
AClass.zeroAll(b);
Display 6.3 Testing Arrays for Equality (part 1 of 2)
1 public class DifferentEquals
2{
3
/**
4
A demonstration to see how == and an equalArrays method are different.
5
*/
6
public static void main(String[] args)
7
{
8
int [] c = new int [10];
9
int [] d = new int [10];
10
int i;
The arrays c and d contain
the same integers in each
index position.
11
for (i = 0; i < c.length; i++)
12
c[i] = i;
Search WWH ::




Custom Search