Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Arrays

  Asked By: James    Date: Oct 28    Category: Java    Views: 577
  

i need your help, i am confuse of using arrays...
can you show me a pattern or the program of an ANAGRAM using
arrays...please...

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Herbert Weaver     Answered 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.

 
Answer #2    Answered By: Richie Smith     Answered On: Oct 28

Now we have an array 'shirt' with 22 slots (0-21). We could say

for (int i = 0; x < 22; x++)
{
System.out.println("The the value of shirt[" + i + "] is: " +
shirt[i]);
//Do some other stuff with shirt[i] si necessaire...
}

 
Didn't find what you were looking for? Find more on Arrays Or get search suggestion and latest updates.




Tagged: