• We just launched and are currently in beta. Join us as we build and grow the community.

Palyndrome in Java

snapnaser

Funny Flash Master
S Rep
0
0
0
Rep
0
S Vouches
0
0
0
Vouches
0
Posts
94
Likes
43
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
This code will show you if the word is Palyndrome or not.

  1. import

    java.util.Scanner

    ;

  2. public

    class

    Palyndrome
  3. {
  4. public

    static

    void

    main(

    String

    [

    ]

    args)
  5. {
  6. Scanner read =

    new

    Scanner(

    System

    .in

    )

    ;

  7. int

    ctr =

    0

    ;

  8. System

    .out

    .print

    (

    "Enter any string: "

    )

    ;
  9. String

    str =

    read.next

    (

    )

    ;

  10. if

    (

    str.length

    (

    )

    +

    1

    >

    3

    )
  11. {

  12. for

    (

    int

    x=

    0

    ,y=

    str.length

    (

    )

    -

    1

    ;

    x<

    str.length

    (

    )

    ;

    x++

    ,y--

    )
  13. {
  14. char

    a =

    str.charAt

    (

    x)

    ;
  15. char

    b =

    str.charAt

    (

    y)

    ;

  16. if

    (

    a==

    b)
  17. {
  18. ctr++;
  19. }

  20. }

  21. if

    (

    ctr==

    str.length

    (

    )

    )
  22. {
  23. System

    .out

    .print

    (

    "The string \"

    "

    +

    str +

    "\"

    is Palyndrome."

    )

    ;
  24. }
  25. else
  26. {
  27. System

    .out

    .print

    (

    "The string \"

    "

    +

    str +

    "\"

    is NOT Palyndrome."

    )

    ;
  28. }

  29. }
  30. else
  31. {
  32. System

    .out

    .print

    (

    "The string \"

    "

    +

    str +

    "\"

    is too SHORT."

    )

    ;
  33. }

  34. }
  35. }

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.

2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


Download
You must upgrade your account or reply in the thread to view the hidden content.
 

452,496

338,535

338,543

Top