-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
please review my code and merge it. thank you!!
- Loading branch information
1 parent
d808d72
commit a68f87e
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import java.util.Scanner; | ||
|
||
public class decToBin { | ||
|
||
public static void decToBinConversion(int n){ | ||
int myNum = n; | ||
int pow = 0; | ||
int binNum = 0; | ||
|
||
while(n > 0){ | ||
int rem = n % 2; | ||
binNum = binNum + (rem * (int)Math.pow(10, pow)); | ||
pow++; | ||
n = n / 2; | ||
} | ||
System.out.println("binary form of " + myNum + " = " + binNum); | ||
|
||
} | ||
public static void main(String args[]){ | ||
Scanner sc = new Scanner(System.in); | ||
|
||
decToBinConversion(7); | ||
|
||
|
||
sc.close(); | ||
} | ||
} |