Java > Logic-1 > specialEleven (CodingBat Solution)

Problem:

We'll say a number is special if it is a multiple of 11 or if it is one more than a multiple of 11. Return true if the given non-negative number is special. Use the % "mod" operator -- see Introduction to Mod

specialEleven(22) → true
specialEleven(23) → true
specialEleven(24) → false


Solution:

public boolean specialEleven(int n) {
    return n % 11 == 0 || n % 11 == 1;
}


9 comments :

  1. I would say this should be

    return n % 11 == 0 || (n % 11 == 1 && n > 11);

    Since 1 is not '1 greater than a multiple of 11'. 0 isn't a multiple of 11. CodingBat accepts 1 as a valid answer but that's not the case.

    ReplyDelete
  2. public boolean specialEleven(int n) {
    return n % 11 <= 1;
    }

    ReplyDelete
  3. public boolean specialEleven(int n) {
    if(n%11 == 0 || n%11==1)
    return true;
    else
    return false;
    }

    ReplyDelete
  4. public boolean specialEleven(int n) {
    int a=n%11;
    if(a<2) return true;
    return false;
    }

    ReplyDelete
  5. return(n >= 0 && (n % 11 == 0) || (n%11 == 1));

    ReplyDelete
  6. public boolean specialEleven(int n) {
    if(n%11 == 0 || n%11==1)
    return true;
    else
    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