Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1735ac9

Browse files
author
Ram swaroop
committed
boolean array puzzle done
1 parent 81092c4 commit 1735ac9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package me.ramswaroop.bits;
2+
3+
import java.util.Arrays;
4+
5+
/**
6+
* Created by IntelliJ IDEA.
7+
*
8+
* @author: ramswaroop
9+
* @date: 6/12/15
10+
* @time: 3:31 PM
11+
*/
12+
public class BooleanArrayPuzzle {
13+
14+
/**
15+
* Change 1 to 0 in an array of length 2 containing
16+
* one 0 and the other either 1 or 0.
17+
*
18+
* @param a
19+
* @return
20+
*/
21+
public static int[] change1To0InArray(int a[]) {
22+
a[a[1]] = a[a[0]];
23+
return a;
24+
}
25+
26+
public static void main(String a[]) {
27+
System.out.println(Arrays.toString(change1To0InArray(new int[]{0, 0})));
28+
System.out.println(Arrays.toString(change1To0InArray(new int[]{0, 1})));
29+
System.out.println(Arrays.toString(change1To0InArray(new int[]{1, 0})));
30+
}
31+
}

0 commit comments

Comments
 (0)