Results 1 to 2 of 2
  1. #1
    blueduiker is offline Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    55
    Rep Power
    0

    Talking to which if statement does this else belong to??

    Java Code:
    public int scoreUp(String[] key, String[] answers) {
    int score = 0;
    for (int i=0; i < key.length ; i++) {
    if (answers[i] != "?"){
    if (key[i].equals(answers[i]))
     score +=4;
    else score--;
    }
    }
    return score;
    }
    which if statement does the else statement belong to?
    the first or second?
    and if possible can you explain why

  2. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Format the code properly, and it becomes pretty clear:
    Quote Originally Posted by blueduiker View Post
    Java Code:
        public int scoreUp(String[] key, String[] answers) {
            int score = 0;
            for (int i=0; i < key.length ; i++) {
                if (answers[i] != "?"){
                    if (key[i].equals(answers[i]))
                        score +=4;
                    else score--;
                }
            }
            return score;
        }
    -Gary-

Similar Threads

  1. If Statement in SQL
    By Steffi1013 in forum JDBC
    Replies: 6
    Last Post: 04-10-2010, 03:19 PM
  2. need help in sql statement
    By chyeeqi in forum JDBC
    Replies: 6
    Last Post: 03-28-2010, 07:49 PM
  3. for statement help
    By helpisontheway in forum New To Java
    Replies: 5
    Last Post: 11-14-2009, 04:14 PM
  4. The if Statement, need some help!
    By Keno777 in forum New To Java
    Replies: 6
    Last Post: 10-24-2009, 12:53 AM
  5. Statement or Prepared Statement ?
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-01-2007, 04:45 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
  •