Results 1 to 3 of 3

Thread: Write program on palindrome in java

  1. #1
    MoralesMyers is offline Senior Member
    Join Date
    Dec 2009
    Posts
    202
    Rep Power
    3

    Default Write program on palindrome in java

    I want to "write program on palindrome in java.” I tried various methods but I unable to write that program.

    Any idea…………

  2. #2
    PowellParker is offline Senior Member
    Join Date
    Dec 2009
    Posts
    210
    Rep Power
    3

    Default

    1) Hi! I hope that my solution for your problem will help you. Write me back if you are satisfied with the code:

    import java.io.*;
    public class Palindro {
    public static void main(String [] args)
    {
    try
    {
    BufferReader obj = new BufferReader(
    new InputStreamReader(System.in));
    System.out.println("Enter the number");
    int p= Integer.parseInt(obj.readLine());
    int x = p;
    int set=0;
    System.out.println("Number: ");
    System.out.println(" "+ p);
    for (int t=0; i<=p; i++)
    {
    int q=p%10;
    p=p/10;
    set=set*10+q;
    t=0;
    }
    System.out.println("After reversing : "+ " ");
    System.out.println(" "+ set);
    if(x == set){
    System.out.print("The Number you entered is palindrome!");
    }
    else{
    System.out.println("Number you entered is not palindrome!");
    }
    }
    catch(Exception e){
    System.out.println(" Number you entered is out of range!");
    }
    }
    }

  3. #3
    PerrySullivan is offline Senior Member
    Join Date
    Dec 2009
    Posts
    209
    Rep Power
    3

    Default

    2) I hope this is easiest code to find palindrome of length five & help you a lot.

    import java.util.Scanner;

    public class Palindrom
    {


    public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String s="";


    System.out.println("Enter no <strong class="highlight">of</strong> length 5");
    if(sc.hasNext())
    s =s+sc.next();
    if(s.length()!=5)
    System.out.println("Wrong Number Enter again");

    if(s.charAt(0)==s.charAt(4) && s.charAt(1)==s.charAt(3))
    System.out.println(""+s+" Is Palindrom");
    else
    System.out.println(s+" Is not Palindrom");

    }
    }

Similar Threads

  1. C# program for palindrome
    By Harvey Lavan in forum Programming
    Replies: 3
    Last Post: 01-10-2012, 11:00 AM
  2. Replies: 2
    Last Post: 05-14-2010, 01:30 PM
  3. Replies: 1
    Last Post: 05-03-2010, 01:37 PM
  4. write sequence data java program
    By Brownchris in forum Programming
    Replies: 1
    Last Post: 01-22-2010, 06:09 PM
  5. C# program for palindrome
    By JacksonPerez in forum Programming
    Replies: 0
    Last Post: 01-13-2010, 06:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48