lunes, 21 de marzo de 2011

Numero Capicua

Logica ---> Capicua.
Presentacion ---> Formulario.

Descarga... click acá
Logica --->Capicua
  •  /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */

    package Logica;

    /*
     *
     * @author Danimortal
     */
    public class Capicua {

        int dato;

    public String Capicua()
    {
        //Variables Locales
        String reverso = "";
        int datoauxiliar;

        datoauxiliar = dato;
        if (datoauxiliar > 10)
        {
            for (int i=0;datoauxiliar>=10;i=i++)
            {
                reverso = reverso + (datoauxiliar % 10);
                datoauxiliar = datoauxiliar / 10;
            }
        }

    reverso = reverso + datoauxiliar;

    return(reverso);
    }

        public int getDato() {
            return dato;
        }

        public void setDato(int dato) {
            this.dato = dato;
        }

     }
Presentacion ---> Formulario.
  • /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */

    package Presentacion;

    import Logica.Capicua;
    import java.io.*;

    /**
     *
     * @author Danimortal
     */
    public class Formulario {

    public static String leer() throws IOException
        {
        InputStreamReader entrada = new InputStreamReader (System.in) ;
        BufferedReader lectura= new BufferedReader(entrada);
        String cadena=lectura.readLine();
        return((cadena));
        }

    public static void main(String arg[]) throws IOException
        {

        Capicua obj1 = new Capicua();
        System.out.println("Digite el Numero a validar:");obj1.setDato(Integer.parseInt(leer()));
         if(Integer.parseInt(obj1.Capicua()) == obj1.getDato())
        {
            System.out.println("EL NUMERO ES CAPICUA");
        }else{
            System.out.println("EL NUMERO NO ES CAPICUA");
        }

        }
    }

No hay comentarios:

Publicar un comentario