I fucking hate java i can’t believe this is the only way to do this

I fucking hate java i can’t believe this is the only way to do this
java programmers are fucking terrible

Attached: 32E476BC-4169-4683-AC6C-DED7E4264A96.jpg (249x189, 17K)

Other urls found in this thread:

npmjs.com/package/is-even
twitter.com/NSFWRedditImage

Are you retarded or what? Of course there are better ways to do that (you don't even need a function)

I do not under the meaning of this post. Can someone explain it to me in a couple of sentences?

stop same fagging
LOW IQ BATE

Looks like java haters are took retarded for java

I'll do it in two words: lazy bait.

If n%2=0 && n / 14 < 1

i am just trying to find a way to get even numbers

should use a Hashset

public static int isEven(int a){
HashSet even = new HashSet(Arrays.asList(0,2,4,6,8,10,12,14));
return even.contains(a);
}

then just add values as needed to the set.

Attached: dorothy.gif (340x223, 1.99M)

>HashSet even = new HashSet(Arrays.asList(0,2,4,6,8,10,12,14));
>return even.contains(a);

oh my bad should be boolean as a return type.

this is doing the exact same thing with less lines of code what the hell is the difference

I've heard sets are more efficient

no, no! what you want is a hashtable. you just hash all of the even numbers into it with value 1 and then query for whatever value you want. this is the optimal solution!

if ((a/2) * 2 == a){
return true;
}

is everyone in this thread retarded?
if a%2 == 0
return true
Or am I falling for the bait

Looks like you're new around here.

You joke but that's actually how java implements the hashset in the standard library

What the fuck does the percentage of 2 have to do with odd and even numbers you fuckwit? Learn math.

Attached: disability-only.jpg (800x600, 141K)

rubbish
you should throw an exception if number is larger than 15

LOLOLOL

Based newfriend

Yep, got baited. Thanks, samefag

if((a%2==0 || a==0) && a

Easy to do with a simple for loop:

for (int k = 0; k < k + 1; k + 2)
System.out.println("k");

saves a long list and even tells you the numbers that will return 1, op.

a

OP's code checks if a number is even or odd.
your code prints "k" in endless loop.

that's the modular operator
i dont care if it's bait you're still a fucking faggot

awful bait

>int k = 0;
>k + 2

you can check if a number is even or odd if it appears on this list

it's endless loop, pajeet
and it's k+=2 not k + 2

your code also return "k" not the numbers, pajeet

public static int isEven(int a) {
return a & 1 == 0;
}

should be a boolean but in any case nice b8 op

public static int isOpAfaggot(int a){
if(a%2!=0)return 1;
else return 0
}

Try adding numbers in Java some time.

Attached: mathsinjava.jpg (674x490, 50K)

I think at this point you out smarted everyone on Jow Forums

if (a+a)/2 == a
return true

public static int isEven(int a) {
Double b = Double.valueOf(a);
Double b2 = b / 2;
String c = b2.toString();
Character d = c.charAt(c.length()-1);
if(d.toString().equals(Integer.toString(0)))
return 1;
else
return 0;
}

There, was that really that hard OP?

return a&0

How does it work? If you give it 4 it will return 0 because 4/2 is 2 not 0

>brainlets using modulo

public boolean isEven(int i) {
return i & 1 == 0;
}

>brainlets declaring non-static methods

Are you mother fuckers dumb. First who the fuck returns a fucking int just return a boolean. Second return n % 2 == 0;

4.0/2 is 2.0, 3.0/2 is 1.5. get it?

well programing is hard work user

>allocating object just to check if number is even

>who the fuck returns a fucking int
C programmers

I think it'd save everyone from confusion if modulo was 'mod' instead of percent sign.

No, brainlets would still get confused.

What does % do here?

Good bait

And that's why you should use C# 8.0 instead of this dinosaur shit. With C# you can simply write
public static int IsEven(int a) =>
a switch {
0 => 1,
2 => 1,
4 => 1,
6 => 1,
8 => 1,
10 => 1,
12 => 1,
14 => 1,
_ => 0
};

Simple, concise and modern.

Memes aside this is actually nice syntactic sugar.

>HashSet even = new
And here is how I know you do not have developer job.
Always use interface.

No need, he's not exposing it anywhere.

Exposing or not - use interface. Always. Not only it is good habit and will make refactoring to later expose ot easier - there is no reason to not use interface.

Module it calculates the remainder after division. So 12 % 7 = 5 where as 12 / 7 = 1 (lets assume an integer context)

What if your function depends on certain access speed patterns and there is no interface for that in the STD? create your own shitty wrapper types? fuck off with that bloat ware EE autism. Interfaces are really only needed for what you "interface" with. That is a library should only talk interfaces but can and should use classes in its implementation freely.

Also lol not using local variable type inference

== nigga

So in this case basically -but if it were a bigger number say 34%7 is 6? And 34/7 is 4.85xxxxxx? Or am I missing the point?

#define EPSILON 1e-9
auto a = 14;

while (a --> 0) {
try {
if (fabs(fmod(a, 2)) < EPSILON)
throw a;
}
catch (int number) {
printf("%d\n", number);
}
}

>while (a --> 0)
I'll be honest this is my favorite way to troll newfags

>implying compiler won't optimize it anyway

Fuck you op, its easy

If(a==even)
Return 1;

You probably forgot a semicolon faggot

!(a & 1)


the patrician way

>I don't know what casting is
>I don't know what interfaces are for either
>lets drop EE buzzword to sound credible
when you have interface you code to interface. If you need something special - cast. If you need something speciall all the time - yes use implementation. If it has no interface - use implementation.
Learn to software develop pajeet.

Even C99 has a bool type though

Lel

Why does this work

>returning an odd value when finds an even value
boy are you a retard or something

This is not well defined

Attached: Screenshot_20190712-163026__01.jpg (1080x1069, 96K)

WoW I wonder how much patience old game developers must have had when they were working on old games like Doom, and they had to write all these even and odd numbers by hand!

Huge props to them

Explain to a non java fag

if a number is odd it's binary representation ends with 1 thus by doing a bit-wise AND operation with 1 a & 1 will return true for an odd number and false for an even one

That's why C++ is better
#include
#include
#include

void addInVector(std::vector& vec, unsigned int n)
{
for(unsigned int i = 0; i

Attached: 1473448508509.png (1000x1000, 215K)

public static int isEven(int a) {
return a & 1 == 0
}

;

return a%2 == 0;

& is a bitwise operator. It checks if the first bit of the variable a is a 1 or a 0. Since even binary numbers all start with 0, the operation a & 1 returns 0. 0 == 0 is true, and returns 1.

Yeah thats correct

I want to believe the sole purpose of this thread is to piss people off and not for serious discussion.

Attached: 1506909488392.jpg (400x400, 25K)

just check if 2 is in the prime factorization of a

that's why i use Javascript, its like java but with all kind of libraries to solve all the difficult shit.

npmjs.com/package/is-even

nub took the nested bait.

>weekly downloads - 45,726

Holy crap I hope that's just a lame OOP joke

Seriously

var a = [''zero','one ','two ','three ','four ', 'five ','six ','seven ','eight ','nine ','ten ','eleven ','twelve ','thirteen ','fourteen ']
for(i; i

>n/14 < 1
Bitch n

you don't know how to code Java dude

if(a ==== even){
return alert("the number is even")
};

That's retarded.
You didn't use exceptions for control flow. This means you didn't write idiomatic Java. This could just as well be C or C++.

Java doesn't have a modulus operator?

You are levels of stupid that I forgot exised

Trust me, I'm an engineer.
bool IsEven(uint8_t number)
{
return !(number

Listen up, if u aren't programming in scratch or brainfuck, are you even considered a programmer?

Making an interpreter, hell even a compiler for Brainfuck would so incredibly easy. Why doesn't every beginner implement one so that they gain experience and confidence?

this

I also hate Java but this is by no means the only way to do this

Well well well