×

# Prime Palindromes easy

 0 import java.io.BufferedReader; import java.io.InputStreamReader; class test { public static boolean ispallin(String n) { StringBuffer a = new StringBuffer(n); if(n.equals(a.reverse().toString())) { return true; } return false; } public static boolean isprime(int n) { if(n==1) { return false; } if(n==2) { return true; } for(int i =2;i<=Math.sqrt(n);i++) { if(n%i==0) { return false; } } return true; } public static void main(String[] args)throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); for(int m=n;m<=1000000;m++) { if(m>3&&m%2==0) { continue; } String str; str = String.valueOf(m); if(ispallin(str) && isprime(m)) { System.out.println(m); break; } } } }  why is it giving wrong answer am i missin something here ?? asked 08 Jul '13, 13:22 2★zargus 176●6●21●36 accept rate: 0% 4★kunal361 6.0k●13●32●72

 1 One mistake that i found: Input:99000 Expected output: 1003001 (mostly) Your ouput: Nothing! :O See this. Hope this helps! :) answered 08 Jul '13, 13:45 1.3k●3●10●25 accept rate: 19% 1 yees got that one :) thnx..! (08 Jul '13, 13:48) zargus2★
 0 sorry.... it was a very silly mistake of me needed to remove the condition of m<=1000000 from the for loop got an ac finally :) answered 08 Jul '13, 13:41 2★zargus 176●6●21●36 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,070

question asked: 08 Jul '13, 13:22

question was seen: 764 times

last updated: 08 Jul '13, 13:48