Java > AP-1 > scoresIncreasing (CodingBat Solution)

Problem:

Given an array of scores, return true if each score is equal or greater than the one before. The array will be length 2 or more.

scoresIncreasing({1, 3, 4}) → true
scoresIncreasing({1, 3, 2}) → false
scoresIncreasing({1, 1, 4}) → true


Solution:

public boolean scoresIncreasing(int[] scores) {
  boolean match = false;
  for (int i = 0; i < scores.length-1; i++) {
    if (scores[i+1] >= scores[i]) 
      match = true;
    else
      return false;
  }
  return match;
}


No comments :

Post a Comment

Follow Me

If you like our content, feel free to follow me to stay updated.

Subscribe

Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?

Upload

Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact