115

public boolean even( int num ) {
if ( num < 0 )
num = -1 * num;
while ( num > 1 )
num = num - 2;
if ( num == 0 )
return true;
else
return false;
}

Comments
  • 23
  • 14
    Wtf
    It isn't even recursive
  • 11
    public int gcd( int a, int b ) {
    if ( a < 0 )
    return gcd( -1 * a, b );
    if ( b < 0 )
    return gcd( a, -1 * b );
    if ( a > b )
    return gcd( a - b, b );
    if ( a < b )
    return gcd( a, b - a );
    return a;
    }

    public boolean even( int num ) {
    if ( gcd( num, 2 ) == 2 )
    return true;
    else
    return false;
    }
  • 4
    Wtf? You actually saw another dev doing that????
  • 3
    The dev should read the operators manual... Ouch
  • 19
    return num & 1 == 0;
  • 3
    this hurts.. physically
  • 5
    I'm so confused as to what this code is even supposed to do. Is it trying to determine whether or not an integer is an even number? :S
  • 2
  • 7
    @abhishekb hmm I normally use number % 2
  • 5
    @DefiniteGoose Couldn't you just:

    public bool even(int number) {

    return (number % 2 == 0);

    }

    (Note: I'm not familiar with Java, which is what I assume this is.)
  • 2
    @DefiniteGoose That's true, somehow I didn't think that far. :P
  • 5
    Okay guys, I've made a much more optimal version /s
  • 3
    @inaba please no.
  • 2
    @inaba What font are you using, if I may ask? :)
  • 3
    @sallai FiraCode
  • 1
    @inaba Thanks! I've seen it a lot of times but never actually found out what it's called :)

    ++'d

    </offtopic>
  • 0
    @inaba God forbid anyone calls this with a negative n or 0
  • 1
    @DustInCompetent I guess I could abs it
Add Comment