I need help with a simple coding write a java method to take

I need help with a simple coding

write a java method to take a positive integer value as its parameter and returns a string of 1s and 0s that represents its binary value

Solution

public class DTB
{
public void decimaltobinary(int num)
{
int a[]=new int[50];
int i=0;
while(num>0)
{
a[i++]=num%2;
num=num/2;
}
for(int j=i-1;j>=0;j--)
{
System.out.print(a[i]);
}}
public static void main(String args[])
{
DTB d=new DTB();
d.decimaltobinary(25);
}
}

This is a java program that converts a possitive integer value to its binary equivalent and prints it .

I need help with a simple coding write a java method to take a positive integer value as its parameter and returns a string of 1s and 0s that represents its bin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site