Java > AP-1 > scores100 (CodingBat Solution)

Problem:

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) {
  for (int i = 0; i < scores.length-1; i++) {
    if (scores[i] == 100 && scores[i+1] == 100)
      return true;
    
  }
  return false;
}


1 comment :

  1. public boolean scores100(int[] scores)
    {
    for(int i = 1; i < scores.length; i++)
    {
    if(scores[i-1] == 100 && scores[i] == 100) return true;
    }

    return false;
    }

    ReplyDelete

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