Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: James Rivera   on Oct 28 In Java Category.

  
Question Answered By: Herbert Weaver   on Oct 28

I will try to do my best to help  you...


First of all, you know that everytime that you need to store a value
you need a var right ?

So imagine that you need a var to save the the home shirt number of
one chelsea player like number 5, ok it have to be integer and you
give to him a name like

int xpto = 5;

Ok , now you have one var with name xpto and value 5 of type integer.

But... if you need to save all the shirts , you will have to create 22
or 24 different variables.. its really bad...

So you can have one(just one) var but with the cappacity to save a
long capacity has you want but respecting a single type.

like :

int[] shirt = int[22];

Now you have a var with 21 positions( dont forget that the index
starts in 0 so you have 22 but the last one is 21 ( 0 to 21 are 22
numbers).

You can access to any row using the name of the array and the index

like shirt[10] = 20 ;

You said that shirt10 have the number 20.

Share: