开发者

Array fundamental

I have one array size of 11 with String, i add some item in it.

Decalration::

 String arr_sound[] = new String[11];

Initialization::

arr_sound[0] = "bike_route.mp3";
    arr_sound[1] = "closed.mp3";
    arr_sound[2] = "exit.mp3";
    arr_sound[3] = "no_parking.m开发者_如何学Cp3";  
                 ....
                 ....
    arr_sound[11] = "touch_and_show.mp3";

Problem if i am initialize with arr_sound[01] = "closed.mp3" give error.any solution ? Thanks


This line:

arr_sound[11] = "touch_and_show.mp3";

Should throw an ArrayOutOfBoundException.

Your array can contain 11 Items as defined.
The first goes into arr_sound[0]
And the 11th and last into arr_sound[10].

arr_sound[11] would be the 12th item.


You should know that in java numbers that start with 0 - are octal numbers.


you should not use code like this:

arr_sound[01] = ...

or

arr_sound[11] = ...

because the index is an int and has to be from 0 to 10


arr_sound[11] = "touch_and_show.mp3";

This will not work if your array has only 11 elements. You need to create an array with 12 elements:

new String[12];


Why are you initializing with O1?

The correct thing should start from 0 because that's the first default index for java, unless you set it otherwise.

arr_sound[0] arr_sound[1] . . . arr_sound[10]

Values that start with 0 are likely octal.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜