# Thread: i can do count, but having problem with array

1. Member
Join Date
Oct 2009
Location
Texas
Posts
7
Rep Power
0

## Solved

i figure it out!
Last edited by judy318; 10-31-2009 at 09:46 AM. Reason: solved

2. Senior Member
Join Date
Jun 2008
Posts
2,563
Rep Power
8
Well, lets see your attempt at the for loop (and use code tags), but as a hint, use p.length rather than a bare number in the for loop declaration.

3. Member
Join Date
Oct 2009
Location
Texas
Posts
7
Rep Power
0
actually i've tried that too. p.lenghth... i think it might be something simple but not getting at this point...i guess goto barns and nobels to see/read book lol
public static void main(String[] args) {

int even=0, odd=0;
int p[]=new int[25];
for (int i=0;i<p.length;i++) p[i]=0;

while (true)
{
int a,b,c,d,e,n;
n=(int)Math.floor(10000+Math.random()*(99999-10000+1));

int x=n;

a=x%10;
x=x/10;
b=x%10;
x=x/10;
c=x%10;
x=x/10;
d=x%10;
x=x/10;
e=x%10;

if(a==e && b==d)
{
p[i]++;
if (p[i]<25)break;
if(n%2==0)even++;
else odd++;

System.out.println(n+"");
} else continue;

}

System.out.println("Number of even palindromes are: "+even);
System.out.println("Number of odd palindromes are: "+odd);

}

4. Senior Member
Join Date
Jun 2008
Posts
2,563
Rep Power
8
Your for loop begins and ends here
Java Code:
`for (int i=0;i<p.length;i++) p[i]=0;`
and all it's doing is setting the elements to 0 (which they already are, by default, anyway). I thought the assignment was to replace the while loop with a for loop. Why haven't you done that (or even tried it).

Edit: And use code tags when posting code. That unformatted stuff is torture to read.

5. Member
Join Date
Oct 2009
Location
Texas
Posts
7
Rep Power
0

## my assignment

write a program to create an array of size 25 and fill it with 5 digit palindromes. print how may of the 25 are even and how many odd. yeap! that is the assignment. i got everything to work but the array thing!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•