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++;
}
}
}
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.