+ 2

What is array? With example

I know the meaning of array including concept but the example vice I m not good in that..plz anyone help to me

10th May 2017, 10:10 AM
Jothi N
Jothi N - avatar
2 Antworten
+ 4
I made a cricket game a few days back, in which I had to store runs scored by 10 different batsmen. I may have used :- int playerOneScore = 28; int playerTwoScore = 80; blah blah lot of time waste. I used :- int[] playerScores = new int[10] ; Well, thats it!!After this whenever one batsmen was out, his score got added to this array using a simple for loop. This made easier for me to make scorecard. Advantage :- Single object is created instead of 10, hence memory is saved, code is faster. In case you want to look at that game, here it is :- https://code.sololearn.com/c56Bnye5KD1E/?ref=app As you can see in line 50 and 51, two 2D arrays are declared. Reason for 2 :- one for player, one for computer Reason for 2D array :- I needed two coloumns, one for storing runs and one for balls.
10th May 2017, 10:40 AM
Meharban Singh
Meharban Singh - avatar
0
ok fine see first of all array is a collection of data of same data type so like we want to store 1 to 5 numbers so then we will use an int type array like :int array[5]={1,2,3,4,5};
10th May 2017, 10:26 AM
prakhar dixit
prakhar dixit - avatar