Decimal To Binary
import java.util.*;
public class practice {
public static void main(String[] args) {
Scanner s =new Scanner(System.in);
int n,b=0,k,i=0;
System.out.println("Enter the Decimal Number to be converted to Binary");
n=s.nextInt();
while(n>0){
k=n%2;
b=b+k*(int)Math.pow(10,i);
n=n/2;
i++;
}
System.out.println("Decimal vlaue of Binary Number is "+b);
}
}
Output:-
Comments
Post a Comment