We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b680555 commit 979324dCopy full SHA for 979324d
Lecture005 Bitwise Operators, For Loops, Operator Precedence & Variable Scoping/MagicNumber.java
@@ -0,0 +1,17 @@
1
+public class MagicNumber {
2
+ // Find the nth Magic Number
3
+ public static void main(String [] args){
4
+ int n = 9;
5
+ int ans = 0;
6
+ int base = 5;
7
+ while(n > 0){
8
+ // Find Last Digit of Binary number by and with 1
9
+ int lastDigit = n & 1;
10
+ ans = lastDigit * base;
11
+ base = base * 5;
12
+ n = n >> 1;
13
+ }
14
+
15
+ System.out.println(" Ans is: " + ans);
16
17
+}
0 commit comments