Home > OS >  Is there a more efficent way to mark the hundreds as incorrect interstates? [duplicate]
Is there a more efficent way to mark the hundreds as incorrect interstates? [duplicate]

Time:09-23

I have a Java problem that requires writing a function to list valid and invalid interstate combinations. The following function passed grading but I was curious if there is a better way to write the check for the flat 100's interval.(100,200, etc.) Below I just brute forced it and it works because there is only 9 values but I would like a more scalable method in case I come across something much larger. Thanks!

    else if (input1 == 100 || input1 == 200 || input1 == 300 || input1 == 400 || input1 == 500 || input1 == 600 || input1 ==700 || input1 == 800 || input1 == 900){
     

CodePudding user response:

public static boolean isValid(int input1) {
    return input1 % 100 == 0;
}
  • Related