File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
src/binary/binCheckOddOrEven Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 5353- [x] Hamming Weight implementation (return 1-bits of a binary representation of a number)
5454- [x] [ Binary to Decimal Converter] ( https://tausiq.wordpress.com/2009/07/27/uab-2005-problem-3-binary-to-decimal-converter/ )
5555- [x] [ Reverse bits] ( https://leetcode.com/problems/reverse-bits/ )
56+ - [x] [ Bit Hacks — Part 1 (Basic)] ( http://www.techiedelight.com/bit-hacks-part-1-basic/ )
57+
5658
5759## Algorithms
5860
170172## To Do
171173
172174- Bits Manipulation
173- - [ ] [ Bit Hacks — Part 1 (Basic)] ( http://www.techiedelight.com/bit-hacks-part-1-basic/ )
174175 - [ ] [ Bit Hacks — Part 2 (Playing with k’th bit)] ( http://www.techiedelight.com/bit-hacks-part-2-playing-kth-bit/ )
175176 - [ ] [ Bit Hacks — Part 3 (Playing with rightmost set bit of a number)] ( http://www.techiedelight.com/bit-hacks-part-3-playing-rightmost-set-bit-number/ )
176177 - [ ] [ Bit Hacks — Part 4 (Playing with letters of English alphabet)] ( http://www.techiedelight.com/bit-hacks-part-4-playing-letters-english-alphabet/ )
Original file line number Diff line number Diff line change 1+ package binary .binCheckOddOrEven ;
2+
3+ import utils .InputReader ;
4+
5+ // The expression n & 1 returns value 1 or 0 depending upon whether n is odd or even.
6+ public class BinaryCheckOddEvenNum {
7+ public static void main (String [] args ) {
8+ System .out .print ("Input a number: " );
9+ int n = InputReader .readInt ();
10+ if ((n & 1 ) != 0 ) {
11+ System .out .println (n + " is odd" );
12+ }
13+ else {
14+ System .out .println (n + " is even" );
15+ }
16+ }
17+ }
You can’t perform that action at this time.
0 commit comments