Ad
  • Custom User Avatar

    if you swap the parameter and the literal, you can avoid unnecessary NPE ;) Good luck with your studies!

  • Custom User Avatar

    This is a good solution, but not universal :( To fix it, you need to use System.lineSeparator() or System.getProperty("line.separator")

    • \n is for unix
    • \r is for mac (before OS X)
    • \r\n is for windows format

    Good luck in your studies! =)

  • Custom User Avatar

    Whenever possible, use switch is the best practice. Firstly, readability, and secondly, switch works more efficiently than if - else chains, since with if else the performer does not know in advance which condition will suit him, everything is calculated in runtime, but when using switch, the performer almost instantly chooses what came up according to the condition :) Good luck in your studies!

  • Custom User Avatar

    You are absolutely right, there is no need for this

  • Custom User Avatar

    The best practice is to write such constructions in reverse:

    word.equals("") -> "".equals(word)

    Why? Because this way we exclude NullPointerException, because "" will never be null, but word does not give such guarantees :) Good luck in learning!

  • Custom User Avatar

    It seems to me that returning Integer.MIN_VALUE is not the most obvious things that the method can do if it does not find the desired value. 0 or -1 would be more appropriate, IMHO :)

  • Custom User Avatar

    Conscious variable names are a sign of professionalism. Keep it up! :)

  • Custom User Avatar

    This is not a project where a full-fledged solution is required, but in any case it is done really competently

  • Custom User Avatar

    According to the condition of the problem, the length of the array is guaranteed to be > 1, in the examples it can be seen that the first element in the incoming array is "thrown out", this is logical, because checking for i % 0 will not make sense. That's why we start the sequence with 1