Social Icons

Friday, July 9, 2010

scoresIncreasing: Solutions for Javabat:27


Question

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 b=false;
  for(int i=1; i<scores.length;i++){
     if(scores[i]>=scores[i-1])
       b=true;
     else{
       b=false;
       break;
     }  
  }
  return b;
}
 
 
Blogger Templates http://slots.to/