View Full Version : Java Programming Class Help

10-01-2008, 12:25 AM
I need to create a class with a method that accepts a charge account number as its argument. The method should determine wheaher the number is valid by comparing it to the following list of valid charge account number.
12345, 23456,34567,45678.
These numbers should be stored in an array. use either a sequntial search or a binary search to locate the number passed as an argument. the method should return true, if the number is found. and false if the number is not found.

Any help would be greatly appreciated.

10-01-2008, 05:50 AM
import java.util.Arrays;

class ChargeAccounts {
private static final int[] validNums = new int[] { 12345, 23456, 34567, 45678 };

public static bool isValid(int num) {
return Arrays.binarySearch(validNums, num) >= 0;