Timeline for What do you get when you multiply 6 by 9? (42)
Current License: CC BY-SA 3.0
23 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jun 14, 2017 at 12:16 | history | edited | marcelovca90 | CC BY-SA 3.0 |
added 2 characters in body
|
Jun 9, 2017 at 8:19 | comment | added | Olivier Grégoire |
@MartinBarker to show a concrete example, if (0) { } else { } won't compile in Java. That's why 0 isn't a valid falsy type.
|
|
Jun 6, 2017 at 14:55 | comment | added | marcelovca90 | @MartinBarker, thanks for the explanation! | |
Jun 6, 2017 at 14:52 | comment | added | Martin Barker | Just a note why the 0 is not false. Java is type safe so 0 is an integer not a boolean and unsafe typecasting is not allowed so you can't use falsy values | |
Jun 4, 2017 at 17:23 | comment | added | marcelovca90 | @OlivierGrégoire Good point, thank you! | |
Jun 4, 2017 at 17:22 | history | edited | marcelovca90 | CC BY-SA 3.0 |
added 61 characters in body
|
Jun 4, 2017 at 16:14 | comment | added | Olivier Grégoire |
You can use currying to spare one byte, and you can get rid of the semicolon as it's not part of the lambda to spare another byte: a->b->a==6&b==9?42:a*b .
|
|
Jun 4, 2017 at 13:45 | comment | added | Riker | @CoffeeandClonazepam ah, okay. | |
Jun 4, 2017 at 4:15 | comment | added | marcelovca90 |
@Riker Try it online! Main.java:4: error: incompatible types: int cannot be converted to boolean
|
|
Jun 4, 2017 at 4:10 | comment | added | marcelovca90 |
@Riker nope, it does not work like that in java. E.g. the snippet int a = 5; if (a) do_some_stuff(); else do_other_stuff(); gives a Type mismatch: cannot convert from int to boolean compilation error. They must be made explicitly with boolean values; refer to SO and ORACLE.
|
|
Jun 4, 2017 at 4:02 | comment | added | Riker | @CoffeeandClonazepam I'm not great at java, but doesn't every number other than 0 evaluate to true? We don't require an explicit cast to boolean, as long as the return value can be casted to the correct boolean output. | |
Jun 4, 2017 at 3:12 | history | edited | marcelovca90 | CC BY-SA 3.0 |
deleted 7 characters in body
|
Jun 4, 2017 at 2:59 | comment | added | marcelovca90 |
@LưuVĩnhPhúc not in Java, because I'd have to write (a^6|b^9)==0 since there is no implicit "different than 0" comparison. The resulting code snippet would be 27 bytes long. Anyways, thanks for the suggestion, and please tell me if I got your tip wrong.
|
|
Jun 4, 2017 at 1:23 | comment | added | phuclv |
as suggested here, using ^ will save you several bytes
|
|
Jun 3, 2017 at 17:39 | history | edited | marcelovca90 | CC BY-SA 3.0 |
added 334 characters in body
|
Jun 3, 2017 at 17:30 | history | edited | marcelovca90 | CC BY-SA 3.0 |
added 20 characters in body
|
Jun 3, 2017 at 5:26 | history | edited | ovs | CC BY-SA 3.0 |
deleted 6 characters in body
|
Jun 2, 2017 at 23:19 | history | edited | marcelovca90 | CC BY-SA 3.0 |
deleted 19 characters in body
|
Jun 2, 2017 at 23:14 | comment | added | marcelovca90 | True, I thought I had to explicitly print the result. Thanks for saving me 17 bytes! | |
Jun 2, 2017 at 23:14 | history | edited | marcelovca90 | CC BY-SA 3.0 |
deleted 19 characters in body
|
Jun 2, 2017 at 23:05 | review | First posts | |||
Jun 2, 2017 at 23:06 | |||||
Jun 2, 2017 at 23:04 | comment | added | ETHproductions |
Welcome to PPCG! I don't know much about Java, but could you remove the System.out.println() call and just let the function return the result?
|
|
Jun 2, 2017 at 23:02 | history | answered | marcelovca90 | CC BY-SA 3.0 |