I am trying to convert an integer to a binary number string, and I wrote the code for it and it compiled. However, I can't seem to write a test file for it, i keep getting an error. I am supposed to write a separate test file that outputs my answer, however I am not sure how to do that. I'm pretty new to Java. Can anyone help me figure out how to fix the error I get?
This is my java code for to convert it.
public String binaryNumber( int j)
{
String n = "";
String a = "";
do
{
a += (j % 2);
j = j/2;
}while (j != 0);
for(int r = (a.length() - 1); r >=0; r--)
{
n += a.charAt(r);
}
return n;
}
public String getN {return n;}
This is my test code :
public class BinaryNumberTest
{
public static void main(String[] args)
{
System.out.println("Result: " + binaryNumber(45));
}
}
binaryNumbermust be static