Java Reference
In-Depth Information
56.
}// method
57.
58.
59.
public int getValue( int c) {
60.
if (indexOK(c)){
61.
return (data[indexingFunction(c)]);
62.
}
63.
else {
64.
return (0);
65.
}
66.
}// method
67.
68.
69.
public int size(){
return (length);
70.
}
71.
72.
73.
private boolean indexOK( int i){
if ((i >= startindex) &&(i<=endindex)){
74.
return ( true );
75.
}
76.
else {
77.
78.
System.out.println("ERROR in FlexArray: Index out of bounds.");
79.
return ( false );
80.
}
81.
}
82.
}
File: its/General/FlexArrayDriver.java
1.
package its.General;
2.
3.
import javax.swing.JFrame;
4.
public class FlexArrayDriver {
5.
public static void main(String[] args) {
6.
7.
// Define a FlexArray with indexing -3,-2,..,2.
8.
// and fill it with iˆ3 at position i .
9.
FlexArray myArray = new FlexArray(-3,2);
for ( int i=-3; i <= 2; i++){
10.
myArray.setValue(i,i*i*i);
11.
}
12.
// Read a certain value
13.
System.out.println("Value at -2 is "+myArray.getValue(-2));
14.
// Read a certain value
15.
System.out.println("Value at 2 is "+myArray.getValue(2));
16.
Search WWH ::




Custom Search