We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b2acf84 commit 250a426Copy full SHA for 250a426
decToBin.java
@@ -0,0 +1,27 @@
1
+import java.util.Scanner;
2
+
3
+public class decToBin {
4
5
+ public static void decToBinConversion(int n){
6
+ int myNum = n;
7
+ int pow = 0;
8
+ int binNum = 0;
9
10
+ while(n > 0){
11
+ int rem = n % 2;
12
+ binNum = binNum + (rem * (int)Math.pow(10, pow));
13
+ pow++;
14
+ n = n / 2;
15
+ }
16
+ System.out.println("binary form of " + myNum + " = " + binNum);
17
18
19
+ public static void main(String args[]){
20
+ Scanner sc = new Scanner(System.in);
21
22
+ decToBinConversion(7);
23
24
25
+ sc.close();
26
27
+}
0 commit comments