Alladaskill17 Posted March 11, 2009 Share Posted March 11, 2009 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 More sharing options...
0 Alladaskill17 Posted March 11, 2009 Author Share Posted March 11, 2009 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 More sharing options...
0 Bookieass Posted March 11, 2009 Share Posted March 11, 2009 (edited) 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 March 11, 2009 by Bookieass Link to comment Share on other sites More sharing options...
0 Bookieass Posted March 11, 2009 Share Posted March 11, 2009 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 More sharing options...
Question
Alladaskill17
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