Skip to content

Commit 250a426

Browse files
authored
Added decToBin.java
Decimal to Binary conversion please review my code and merge it. thank you!!
1 parent b2acf84 commit 250a426

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

decToBin.java

+27
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)