Java Reference
In-Depth Information
msgSize 13
interface G
counter 7
localCounter 1
21.
For this last experiment, you will work with arrays. Edit the HelloWorld
source file and add these Java statements to the end of the previous statement.
Enter the checkIntArray() method inside the brackets that define the class.
// Create an array of five error codes.
int[] errorNumbersIO = {1, 2, 10, 22, 23};
// Test if any are equal to 30.
checkIntArray (errorNumbersIO);
}
// Test if any integers in the passed array are equal to 30.
static void checkIntArray (int[] intArray) {
System.out.println ();
for (int x = 0; x < intArray.length; x++) {
if (intArray[x] == 30) {
System.out.println ("Found '30' at index " + x);
break;
}
else
{
System.out.println ("error Number " + x + " = " +
intArray[x]);
}
}
}
22. Save these modifications as a text file, and then compile the class in the
DOS command window. (You may need to add this statement import
java.util.* ; to the beginning of your HelloWorld class.)
➔ javac HelloWorld.java
➔ java HelloWorld
error Number 0 = 1
error Number 1 = 2
error Number 2 = 10
error Number 3 = 22
error Number 4 = 23
Search WWH ::




Custom Search