Skip to content

Commit

Permalink
Added decToBin.java
Browse files Browse the repository at this point in the history
please review my code and merge it.
thank you!!
  • Loading branch information
gulatikeshav authored Oct 31, 2023
1 parent d808d72 commit a68f87e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions decToBin.java
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();
}
}

0 comments on commit a68f87e

Please sign in to comment.