Follow By Email

domingo, 28 de marzo de 2010

Palíndromas Java

 1 
 2 package palindromas;
 3 
 4 import java.io.BufferedReader;
 5 import java.io.IOException;
 6 import java.io.InputStreamReader;
 7 
 8 
 9 public class Palindromas 
10 {
11 
12 
13     public static void main(String[] args) throws IOException 
14     {
15         String texto;
16         int i;
17         int j;
18         boolean esPalindroma = true;
19                 
20         InputStreamReader ISR = new InputStreamReader(System.in);
21         BufferedReader bftexto = new BufferedReader(ISR);
22         
23         texto = bftexto.readLine();
24         
25         j=texto.length()-1;
26         for (i=0;i<texto.length() && j>=i;i++)
27             if (!texto.substring(i,i+1).equals(texto.substring(j,j+1)))
28                 esPalindroma = false;
29             else
30                 j = j - 1;
31         
32         if (esPalindroma)
33             System.out.println("La palabra "+texto+" es palindroma");
34         else
35             System.out.println("La palabra "+texto+" no es palindroma");
36         
37         
38         
39     }
40 }

No hay comentarios:

Publicar un comentario