Results 1 to 2 of 2

Thread: Java Programming Class Help

  1. #1
    Join Date
    Feb 2008
    Posts
    90
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default Java Programming Class Help

    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.
    Thanks.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    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;
      }
    }
    Last edited by Twey; 10-01-2008 at 04:58 AM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •