• 0

[JAVA]


Question

Yes, I am back with another Java Question.

I need help finding Prime Palindrome numbers, the first 100 actually.

Then I can just simply print them 10 per row, aligning them a few spaces apart.

Any help with logic as far as how I could go about finding a prime palindrome? =/

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Working on Prime numbers right now.

I have this but it is just a quick, incomplete code:

   import java.util.Scanner;
	public class PalindromicPrime
   {
	   public static void main(String[]args){
		 Scanner input = new Scanner(System.in);

		 System.out.println ("Please type a number:");	  
		 int Num = input.nextInt();

		 {
			boolean prime = true;
			int limit = (int) Math.sqrt ( Num );  

			for ( int i = 2; i <= limit; i++ )
			{
			   if ( Num % i == 0 )
			   {
				  prime = false;
				  break;
			   }
			}
		 }
	  }
   }

Link to comment
Share on other sites

  • 0
Yes, I am back with another Java Question.

I need help finding Prime Palindrome numbers, the first 100 actually.

Then I can just simply print them 10 per row, aligning them a few spaces apart.

Any help with logic as far as how I could go about finding a prime palindrome? =/

How about this.... mind for C# code

//let say input number is integer stored in variable : number
// we need to check whether it is a prime number or not

int count =0;

for(int i=1;i<number:i++)
{
		int divident =number%i;
		 if(divident ==0)
		{
			   count = count +1
		 }

}

if(count==2)
{
//the number is prime
}

after this cast into string and do the following

bool CheckPalindrome (string CheckString)
{
	 if (CheckString == null || CheckString.Length == 0) 
	 {
		return false;
	 }
	 for (int i = 0; i < CheckString.Length / 2; i++)
	 {
		 if (CheckString[i] != CheckString[CheckString.Length - 1 - i])
		 {
			return false;
		 }
	 }
	 return true;
}

Hope its helps.....

Edited by Bookieass
Link to comment
Share on other sites

  • 0
Working on Prime numbers right now.

I have this but it is just a quick, incomplete code:

   import java.util.Scanner;
	public class PalindromicPrime
   {
	   public static void main(String[]args){
		 Scanner input = new Scanner(System.in);

		 System.out.println ("Please type a number:");	  
		 int Num = input.nextInt();

		 {
			boolean prime = true;
			int limit = (int) Math.sqrt ( Num );  

			for ( int i = 2; i <= limit; i++ )
			{
			   if ( Num % i == 0 )
			   {
				  prime = false;
				  break;
			   }
			}
		 }
	  }
   }

U need two for loops one for number times the loop should run and one nested inside it which actually defines whether the number is prime or not

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.