# i can do count, but having problem with array

• 10-29-2009, 08:47 AM
judy318
Solved
i figure it out!
• 10-29-2009, 08:49 AM
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.
• 10-29-2009, 09:02 AM
judy318
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);

}
• 10-29-2009, 09:10 AM
`for (int i=0;i<p.length;i++) p[i]=0;`