我的试错代码出现问题。它是我需要它做的硬编码...数组被设置为在运行时获得随机二进制。我想隔离问题,但它永远不想打印分子和分母的价值!所以我的假设是它永远不会得到上述值。
我对某些内容进行了硬编码,因为我想看看这是否有效,将0和1的数组分开。我将前半部分(8位)转换为字符串,然后将其解析为分子。我对第二组8位做了同样的事情,并将其解析为分母。然而,它不起作用,我很难过。该数组应该包含16个值(元素: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);
}
}
}
}
有关为什么不起作用的任何建议?干杯! TG52。