Home > Back-end >  Existing code as follows: int [] a=new int [100]. Is a [50] value, please? Why is that?
Existing code as follows: int [] a=new int [100]. Is a [50] value, please? Why is that?

Time:09-19

Is a [50] value, please?

CodePudding user response:

0 bai, you are just the new array has a length of 100, there is no set value, how much is a 0

CodePudding user response:

A [50] is null, you just create a length of 100 int array, there is no assignment

CodePudding user response:

Because it is in the heap, so new JVM automatically to array assignment,
Int type definition of an array, initialize the default is 0
Of the definition of type String array, the default value is null
Char array type definition, the default value is 0, the corresponding characters
Double array type definition, the default value is 0.0
Array of float type definition, the default value is 0.0
Array of Boolean type definition, the default value is false

CodePudding user response:

reference pinoco reply: 3/f
because it is in the heap, so new JVM automatically to array assignment,
Int type definition of an array, initialize the default is 0
Of the definition of type String array, the default value is null
Char array type definition, the default value is 0, the corresponding characters
Double array type definition, the default value is 0.0
Array of float type definition, the default value is 0.0
Array of Boolean type definition, the default value is false

So when you run the code in eclipse, what to write!

CodePudding user response:

reference 4 floor m0_50665479 response:
Quote: reference pinoco reply: 3/f
because it is in the heap, so new JVM automatically to array assignment,
Int type definition of an array, initialize the default is 0
Of the definition of type String array, the default value is null
Char array type definition, the default value is 0, the corresponding characters
Double array type definition, the default value is 0.0
Array of float type definition, the default value is 0.0
Array of Boolean type definition, the default value is false

So when you run the code in eclipse, what to write!
is in the main method to create an array, and then you through the subscript value such as a [50]=1, then you have to output there are other watch yourself, or output can know the result, of course, this assignment after a [50] output is 1

CodePudding user response:

0, because you just initialization and assignment
  • Related