Yahoo Answers is shutting down on 4 May 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

convert C++ statement to java?

static final String VERSIONS[VERSION_LEN][2][STR_LEN] = {{"3.0", "5"}, {"2.0", "6"}, {"4.0", "7"}};

4 Answers

Relevance
  • 1 decade ago
    Favourite answer

    CORRECT STATEMENT:

    final String VERSIONS[][] = new String[][]{{"3.0", "5"}, {"2.0", "6"}, {"4.0", "7"}};

    If you want to define a three dimensional array, it would be like:

    final String VERSIONS[][][] = new String[][][] {{{"3.0", "5"}, {"2.0","6"}, {"4.0", "7"}},{{"3.0", "5"}, {"2.0", "6"}, {"4.0", "7"}},{{"3.0", "5"}, {"2.0", "6"}, {"4.0", "7"}}};

    >> You can declare it as static final if you are declaring it outside a method.

    >> We do use UPPERCASE in variable declarations if the variable is CONSTANT. Using final makes a variable constant, so you are right declaring the variable VERSIONS in uppercase.

    >> Constant variable means you can't change the value of the variable.

  • 1 decade ago

    static final String[ ][ ] VERSIONS = {{"3.0", "5"}, {"2.0", "6"}, {"4.0", "7"}};

    I think you muffed-up with the static final. That's a Java thing (although C++ does have static, but it does something quite different). So, I left that because I think the array notation is what you were really after. Note that the String has one dimension of its own, so you don't have to declare it, unlike char* arrays that would have 3 dimensions in C++.

    And no Java programmer would ever use all caps in a variable name. All lowercase yes, but not upper.

  • 1 decade ago

    Good answers before my post. Just to clarify something tho...

    static cause the java compiler to init that var first and if the var isn't declared, the var gets a default value.

    static myInt; // = 0

    static myString; // = ""

    static myFloat; // = 0.0f

    static myObject; // = null

    and so on so forth, and then for the concept of making constants that would include the modifier 'final'

    static final String MY_STRING = "a string"; // makes a constant

    by java coding convention, constants are ALL_CAPS

    if you declare a static final without a value, it will be null or zero and you can't change it later in your code.

  • 1 decade ago

    final is NOT a C++ keyword (it is infact a java keyword).

Still have questions? Get answers by asking now.