问题
I am having trouble with my trial-and-error code. It's hard coded for what I am needing it to do... where the array is set to get random binary when it's ran. I wanted to isolate the problem, but it never wants to print numerator and denominator's values! So my assumption is it's never getting the said values.
I hard-coded something because I wanted to see if this would work, dividing an array of 0's and 1's. I converted the first half (of 8 bits) to a string, then parsed it to numerator. I did the same for the second set of 8-bits, and parsed it to the denominator. However, it's not working and I am stumped. The array is supposed to hold 16 values (elements : 0-15).
package runTests;
import java.util.Arrays;
public class runTestGetBinaryStrands {
protected static int getBits[] = {1,0,1,1,0,1,0,0,0,1,1,0,1,0,1,0};
double numerator, denominator, x, y;
public static void main (String[] args) {
runTestGetBinaryStrands test = new runTestGetBinaryStrands();
test.getNumber(null, getBits);
}
public void getNumber(String convert, int[] tempBinary) {
/*Should get 16 integers at most in the array at a time & divide
* by 2 to seperate/parse the values.*/
//getBits = new int [16];
for (int i = 0; i > getBits.length; i++) {
for(int j = 0; j < getBits.length; j++) {//start at index 0 to 7 = 8.
tempBinary = Arrays.copyOfRange(getBits, 0, 7); //Get first set of 8 elements.
convert = tempBinary.toString();
numerator = Integer.parseInt(convert); //converts string to one whole section in
System.out.println("See Numerator's value: " + numerator);
tempBinary= Arrays.copyOfRange(getBits, 8, 15); //Get Second set of 8 elements.
convert = tempBinary.toString();
denominator = Integer.parseInt(convert); //converts string to one whole section in.
System.out.println("See Denominator's value: " + denominator);
}
}
}
}
Any advice on why this isn't working? Cheers! TG52.
来源:https://stackoverflow.com/questions/29334506/dividing-array-in-half