+ 7
Java Problem
In Java, why (num&1)==1 throwing error instead of giving answer 1?
6 odpowiedzi
+ 2
try to do like this
public class EvenOddBitwise {
public static void main(String[] args) {
int number = 65;
if((number & 1) == 1) {
System.out.println(number + " is Odd."); }
else {
System.out.println(number + " is Even."); } } }
+ 20
Every odd number have 1 at the end of its binary representation!
public static boolean isEven(int num) {
return (num & 1) == 0;
}
// (number % 2) or (number & 1)
+ 20
Bitwise operators Java
Bitwise AND "&" --> returns true if and only if both arguments are true!
1 & 1 = 1
0 & 0 = 0
0 & 1 = 0
+ 7
Thankyou friends for help
+ 6
Hello, Ajay Agrawal !
Please, read the lessons from SoloLearn so that the problems do not arise any more.
https://www.sololearn.com/learn/Java/2144/
https://www.sololearn.com/learn/Java/2143/
+ 2
you can use (num%2) to find Even/Odd
It would be better if you put your code in the question.