Ad
Arrays
Code
Diff
  • public class Kata {
        
        public static int speedLimit(int speed, int[] signals) {
          int penalty = 0;
          
          for (int signal : signals){
            if (speed > signal) {
              if(speed - signal >= 10 && speed - signal < 20) {
                penalty += 100;            
              } else if(speed - signal < 30) {
                penalty += 250;
              } else if (speed - signal >= 30) {
                penalty += 500;
              }
            }
          }
          
          return penalty;
        }
    }
    • public class Kata {
    • public static int speedLimit(int speed, int[] signals) {
    • int penalty = 0;
    • for (int i = 0; i < signals.length; i++){
    • if (speed > signals[i]){
    • if (speed - signals[i] >= 30){
    • penalty += 500;
    • } else if (speed - signals[i] >= 20 && speed - signals[i] < 30){
    • for (int signal : signals){
    • if (speed > signal) {
    • if(speed - signal >= 10 && speed - signal < 20) {
    • penalty += 100;
    • } else if(speed - signal < 30) {
    • penalty += 250;
    • } else if (speed - signals[i] >= 10 && speed - signals[i] < 20){
    • penalty += 100;
    • } else if (speed - signal >= 30) {
    • penalty += 500;
    • }
    • }
    • }
    • return penalty;
    • }
    • }