Results 1 to 2 of 2
  1. #1
    anthonym2121 is offline Member
    Join Date
    Apr 2009
    Posts
    17
    Rep Power
    0

    Exclamation [SOLVED] indexing an element in an array help!

    Java Code:
    if(input.equals(choices[1])){
                  accountNum = JOptionPane.showInputDialog("What is your account number?");
                  result = getAccountIndex(accountNum, accountNumber[i]);
                  makeDeposit(accountNumber[i],accountBalance[i], creditLimit[i]);
                }
                if(input.equals(choices[2])){
                  accountNum = JOptionPane.showInputDialog("What is your account number?");
                  result = getAccountIndex(accountNum, accountNumber[i]);
                  makeWithdrawal(accountNumber[i],accountBalance[i], creditLimit[i]);
                }
    I seem to be getting an error on the line "result = ...." on both 'if' statements that says:

    Error: getAccountIndex(java.lang.String,java.lang.String[]) in A5Q1ummadhoa cannot be applied to (java.lang.String,java.lang.String)

    I think I may be overthinking the situatuation.

    Java Code:
    public static int getAccountIndex(String key, String accountNumber[]){
           int result = -1;
           
           for(int i=0;i<accountNumber.length;i++){
            
             if(key.equals(accountNumber[i])){
              return i; 
             }
             else System.out.println("Invalid account number.");
           }
           return result;
         }

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    you are passing in 2 strings as arguments. your method is expecting a string and an array of strings.

Similar Threads

  1. Replies: 1
    Last Post: 03-31-2009, 07:40 AM
  2. adding list to an array element
    By Preethi in forum New To Java
    Replies: 5
    Last Post: 09-25-2008, 05:23 AM
  3. Lucene Re-Indexing
    By connect2srinath in forum Lucene
    Replies: 1
    Last Post: 05-11-2008, 06:35 PM
  4. Unique element in an array
    By revathi17 in forum New To Java
    Replies: 2
    Last Post: 12-31-2007, 09:44 AM
  5. Max element in an Array
    By mew in forum New To Java
    Replies: 5
    Last Post: 12-03-2007, 06:26 PM

Posting Permissions

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