简体   繁体   中英

Java 3D out of bounds

I am having problems accessing the values inside the 3d array. Sometimes it givese correct values but sometimes it gives me random nos. that does not exist inside the array.

import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        String[][] strData = {{"0022", "Mercado, Jennylyn"},
                              {"0324", "Collins, Max"},
                              {"0044", "Torres, Andrea"},
                              {"3365", "Pinto, Sam"},
                              {"5463", "Zamora, Gwen"}};

        int[] intEmpNo = {0022, 0324, 0044, 3365, 5463};

        double[][][] dblData = {{{0324, 20000},
                                 {3365, 50000}, 
                                 {0022, 30000}, 
                                 {0044, 27000}},

                                {{3365, 15200},
                                 {0022,  7800},
                                 {0324,  9350}},

                                {{3365,  8000},
                                 {0044, 12300}}};

        int intShit = 4;

        for(int intLoop = 0; intLoop < 5; intLoop++, intShit--){
            System.out.print(strData[intLoop][0] + " " + strData[intLoop][1] + " ");
            System.out.print(dblData[0][2][0] + "\n" );
        }
    }  

In Java if you put 0's in front of numbers they are treated as OCTAL numbers by the compiler (base-8). 0022 is 22 in base-8 and 18 in base-10. This is then cast to a double and stored as 18.0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM