Decimal to Binary Number in JAVA
Decimal to Binary Number
Example : Input : 13
Output : 1101
Program given Below :-
The video link of this program is provided at the end of this post.
Program :-
import java.io.*;
import java.util.*;
class Binary
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int n,p,a;
String str="";
System.out.println("Enter Number to Convert it into Binary");
n= in.nextInt();
p=n;
while(p>0)
{
a=p%2;
str=a+str;
p=p/2;
}
System.out.println("Original Number : "+n);
System.out.println("Binary Form : "+str);
}
};
The video link of this program is provided at the end of this post.
import java.util.*;
class Binary
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
int n,p,a;
String str="";
System.out.println("Enter Number to Convert it into Binary");
n= in.nextInt();
p=n;
while(p>0)
{
a=p%2;
str=a+str;
p=p/2;
}
System.out.println("Original Number : "+n);
System.out.println("Binary Form : "+str);
}
};
Comments
Post a Comment