i can do count, but having problem with array

Printable View

• 10-29-2009, 07:47 AM
judy318
Solved
i figure it out!
• 10-29-2009, 07:49 AM
masijade
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, 08: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, 08:10 AM
masijade
Your for loop begins and ends here
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.
• 10-29-2009, 09:23 PM
judy318
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!