-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwelvefive.java
More file actions
38 lines (36 loc) · 847 Bytes
/
Copy pathtwelvefive.java
File metadata and controls
38 lines (36 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
*Class
*/
public class twelvefive {
/**
* Main method that calls the recursive method with param inputs
*/
public static void main (String[] args) {
writeBinary(999999999);
System.out.printf("\n");
writeBinary(44);
System.out.printf("\n");
writeBinary(-1);
System.out.printf("\n");
writeBinary(0);
System.out.printf("\n");
writeBinary(9);
System.out.printf("\n");
writeBinary(2);
System.out.printf("\n");
writeBinary(1);
}
/**
* @param nums is an integer
* if the param input is less than 2 then we print the input
* else we call the method recursivly and print the remainder of our input
*/
public static void writeBinary (int nums){
if (nums < 2) {
System.out.print(nums);
} else {
writeBinary(nums / 2);
System.out.print(nums % 2);
}
}
}