I have created a function in which I am sending data through array along its index so that particular value should convert into binary, but I don't know whether I am correctly sending and returning array.
my code:
package GA;
public class test {
public void chr_intval(){
double [] array = new double[100] ;
int i=1;
array[i] = 4;
System.out.println(Genes(array,i)); // print the value contain array[1] in binary
}
@SuppressWarnings("null")
public double[] Genes(double[] j,int i){ // get the value from 1st index that is 4 hardcoded
double [] a1=null;
int k=9;
//a1[k]=0;
double d=j[i];
while(d>1)
{
a1[k--]=d%2;
d=d/2;
}
return a1;// return the value in binary that is 100
}
public static void main(String[] args) {
test a = new test();
a.chr_intval();
}
}
at console:
Exception in thread "main" java.lang.NullPointerException
at java.io.Writer.write(Unknown Source)
at java.io.PrintStream.write(Unknown Source)
at java.io.PrintStream.print(Unknown Source)
at java.io.PrintStream.println(Unknown Source)
at GA.test.chr_intval(test.java:10)
at GA.test.main(test.java:41)