FHTW Berlin |
So, we need to get our brains back in gear for another semester! I want to do this little exercise with you to help you get back into Java-Mode and for you to see if JBuilder has gotten any better in the new version. We will do this lab the first week, section 1 will be in the lab VG 212 in block 3 and section 2 in block 4.
Work in groups of two and refer to the following program for parts 1-3:
import java.applet.Applet;
import java.io.*;public class WakeUp extends Applet {
public final static int SIZE = 100;
int find(int[ ] A) {
int j;
for ( j = 0; j < SIZE; j++ ) {
if (A[j] < 0) {
return j;
}
}
return -1;
}public void init( ) {
int[] A = new int[SIZE];
int i;for (i = 0; i < SIZE; i++) A[i] = i*i;
A[17] = -A[17];System.out.println("What you are looking for is = " +
find(A));
}
}
int find(int[ ] A) { int i=0; while ((A[i] >= 0) && (i
< SIZE)){
return (i < SIZE) ? i : -1;
|
Are there any flaws in the implementation of this program? If there
are, suggest a way to fix the program. If not, explain why.
int find(int[ ] A) { int i, result; result = -1; |
Letzte Änderung: 15.03.03 - 22:23 |