Social Icons

Monday, July 12, 2010

scores100 : Solutions for Javabat : 29


Question

Given an array of scores, return true if there are scores of 100 next to each other in the array. The array length will be at least 2.

scores100({1, 100, 100}) → true
scores100({1, 100, 99, 100}) → false
scores100({100, 1, 100, 100}) → true

Solution

public boolean scores100(int[] scores) {
  boolean b=false;
  for(int i=0; i<scores.length;i++){
     if(scores[i]==100 && i+1<scores.length && scores[i+1]==100)
     {
        b=true;
        break;
     }
     else
       b=false;
  }
  return b;
}
 
 
Blogger Templates http://slots.to/