Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Prime Palindrome Assignment

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Prime Palindrome Assignment

    I would like for the boundary variable to increment every time the program
    goes inside of the if statement in the printCount method-- in this way
    boundary will stop the for loop in main when boundary reaches 199.

    If you see anything wrong with my code, please let me know. Thanks!



    public class Emirp
    {
    public static void main(String[] args)
    {
    int i = 0;
    int iReverse = 0;
    int boundary = 0;

    for(i = 13; boundary < 200; i++)
    {
    String s = "";
    iReverse = 0;
    s = Integer.toString(i);
    int index = s.length();

    reverse(s, index);
    iReverse = Integer.parseInt(reverse(s,index));
    }
    }
    public static String reverse(String s, int index)
    {
    if (index > 0)
    {
    return s.charAt(--index) + reverse (s, index);
    }
    else
    return "";
    }
    public static boolean isPrime(int integer)
    {
    for(int value = (integer - 1); value > 1; value--)
    {
    if (integer % value == 0)
    {
    return false;
    }
    }
    return true;
    }
    public static void printCount(int original, int reversed)
    {
    if(isPrime(original) && isPrime(reversed))
    {
    System.out.print(original + " ");
    main.boundary++;
    }
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Prime Palindrome Assignment

    Does the code do what you want? If not please explain what the problem is. Show output from the program to help us understand what the program is doing. Add comments to the output describing what you want the output to be.

    If you are getting errors, please post the full text of the error messages.

Similar Threads

  1. Testing for a Palindrome
    By ryan.sampson in forum Algorithms & Recursion
    Replies: 12
    Last Post: November 6th, 2011, 08:01 PM
  2. Palindrome program help
    By timm1371 in forum Algorithms & Recursion
    Replies: 2
    Last Post: October 13th, 2011, 09:31 AM
  3. stack Palindrome , java
    By Faha in forum Object Oriented Programming
    Replies: 1
    Last Post: May 3rd, 2011, 04:20 PM
  4. Palindrome
    By mag12203 in forum Algorithms & Recursion
    Replies: 13
    Last Post: December 20th, 2010, 08:28 PM
  5. Palindrome Stacks
    By mgutierrez19 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 7th, 2010, 03:05 AM

Tags for this Thread