Results 1 to 5 of 5
  1. #1
    judy318 is offline Member
    Join Date
    Oct 2009
    Location
    Texas
    Posts
    7
    Rep Power
    0

    Default Solved

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

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    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. #3
    judy318 is offline Member
    Join Date
    Oct 2009
    Location
    Texas
    Posts
    7
    Rep Power
    0

    Default

    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. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    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. #5
    judy318 is offline Member
    Join Date
    Oct 2009
    Location
    Texas
    Posts
    7
    Rep Power
    0

    Red face 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!

Similar Threads

  1. Array count number Occurances
    By gwithey in forum New To Java
    Replies: 2
    Last Post: 04-17-2009, 08:34 PM
  2. Returning array problem.
    By Chase in forum New To Java
    Replies: 4
    Last Post: 10-21-2008, 09:07 PM
  3. array problem
    By oceansdepth in forum New To Java
    Replies: 3
    Last Post: 04-05-2008, 02:25 AM
  4. array problem
    By wats in forum New To Java
    Replies: 1
    Last Post: 12-12-2007, 07:08 AM
  5. array problem
    By Albert in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 01:13 AM

Posting Permissions

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