Dividing Array in half

情到浓时终转凉″ 提交于 2020-01-25 11:04:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!