1
1
package com .company .Lecture7 ;
2
2
3
- //import javafx.scene.transform.Scale;
4
-
5
3
import java .lang .reflect .Array ;
6
4
import java .util .Arrays ;
7
5
import java .util .Scanner ;
@@ -10,24 +8,23 @@ public class Bitwise_Examples {
10
8
public static void main (String [] args ) {
11
9
Scanner s = new Scanner (System .in );
12
10
13
- // String[] any = s.nextLine().trim().split(" ");
14
- // int[] nums = new int[any.length];
15
- // for (int i = 0; i < any.length ; i++) {
16
- // nums[i] = Integer.parseInt(any[i]);
17
- // }
18
- // System.out.println(Arrays.toString(nums));
19
- // System.out.println(5 & 11);
20
- // System.out.println(5 | 11);
11
+ String [] any = s .nextLine ().trim ().split (" " );
12
+ int [] nums = new int [any .length ];
13
+ for (int i = 0 ; i < any .length ; i ++) {
14
+ nums [i ] = Integer .parseInt (any [i ]);
15
+ }
16
+ System .out .println (Arrays .toString (nums ));
17
+ System .out .println (5 & 11 );
18
+ System .out .println (5 | 11 );
19
+
20
+ int [] num2 = {2 ,1 ,8 ,1 ,8 ,2 };
21
+ int res = oddOcc (num2 );
22
+ System .out .println (res );
21
23
22
- // int[] num2 = {2,1,8,1,8,2};
23
- // int res = oddOcc(num2);
24
- // System.out.println(res);
25
- //
26
- // System.out.println(countOne(15));
27
- // toggle_basic(14);
28
- // toggle(14);
24
+ System .out .println (countOne (15 ));
25
+ toggle_basic (14 );
26
+ toggle (14 );
29
27
System .out .println (power (3 ,2 ));
30
-
31
28
}
32
29
33
30
public static int oddOcc (int [] nums ){
@@ -39,7 +36,7 @@ public static int oddOcc(int[] nums){
39
36
}
40
37
41
38
public static boolean isOdd ( int n ){
42
- return (n & 1 ) == 0 ;
39
+ return (n & 1 ) == 1 ;
43
40
//If returns 1 : odd else even.
44
41
}
45
42
@@ -59,7 +56,7 @@ public static void toggle_basic (int n){
59
56
int num = 0 ,place =1 ;
60
57
while (n >0 ){
61
58
if ((n & 1 )==0 ){
62
- num = num + 1 * place ;
59
+ num = num + place ;
63
60
}
64
61
place *= 2 ;
65
62
n = n >> 1 ;
0 commit comments