i figure it out!
Printable View
i figure it out!
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.
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);
}
Your for loop begins and ends here
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).Code:for (int i=0;i<p.length;i++) p[i]=0;
Edit: And use code tags when posting code. That unformatted stuff is torture to read.
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!