miércoles, 30 de octubre de 2013
CODIGOS JAVA
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
class palindromo1{
public static void main(String args[])throws IOException
{
InputStreamReader jose = new InputStreamReader (System.in);
BufferedReader luis = new BufferedReader (jose);
int contador;
int x;
String introducir;
do{
System.out.print("\n \n"+"\tINSERTA UNA FRASE Y TE DIRE SI ES PALINDROMO"+
"\n escribe: ");
String cadena=luis.readLine();
char CADENA[]=new char[cadena.length()];
char NUEVO[]=new char[cadena.length()];
System.out.print("\n\t ***FRASE SIN ESPACIOS*** \n\n");
//***************sin espacios*******************************
String s = cadena.substring(0,0);
for (int i=0; i<cadena.length(); i++) {
if (cadena.charAt(i) != ' ')
s+= cadena.charAt(i);
}
System.out.println(" "+s);
//***************************************************************
System.out.print("\n \t***CADENA NORMAL***\n \n");
//llenamos el vector CADENA*************************
for(int a=0; a<s.length(); a++){
CADENA[a]=s.charAt(a);
System.out.print((char)179+" "+CADENA[a]+" ");
}
//¨¨**********************************************
System.out.print("\n \n\t***CADENA INVERTIDA***\n\n");
////********se voltea el vector***********************************
for(int J=0; J<=s.length()-1; J++){
NUEVO[J]= CADENA[(s.length()-1)-J];
System.out.print((char)179+" "+NUEVO[J]+" ");
}
System.out.println("\n\n ");
/////////////////COMPARACION
contador=0;
x=0;
for(int j=0; j<=s.length()-1; j++)
{
if( NUEVO[j]==CADENA[j])
{
x=x+1;
}
if(x==s.length())
{
System.out.print("\n ES PALINDROMO \n");
break;
}
else
contador=contador+1;
if(contador==s.length())
{
System.out.println(" NO PALINDROMO!!!!");
}
}
System.out.print("\nDECEAS INTRODUCIR OTRA FRASE? SI/NO = ");
introducir = luis.readLine();
}while (introducir.equalsIgnoreCase("SI"));
}
}
import java.io.InputStreamReader;
import java.io.BufferedReader;
class palindromo1{
public static void main(String args[])throws IOException
{
InputStreamReader jose = new InputStreamReader (System.in);
BufferedReader luis = new BufferedReader (jose);
int contador;
int x;
String introducir;
do{
System.out.print("\n \n"+"\tINSERTA UNA FRASE Y TE DIRE SI ES PALINDROMO"+
"\n escribe: ");
String cadena=luis.readLine();
char CADENA[]=new char[cadena.length()];
char NUEVO[]=new char[cadena.length()];
System.out.print("\n\t ***FRASE SIN ESPACIOS*** \n\n");
//***************sin espacios*******************************
String s = cadena.substring(0,0);
for (int i=0; i<cadena.length(); i++) {
if (cadena.charAt(i) != ' ')
s+= cadena.charAt(i);
}
System.out.println(" "+s);
//***************************************************************
System.out.print("\n \t***CADENA NORMAL***\n \n");
//llenamos el vector CADENA*************************
for(int a=0; a<s.length(); a++){
CADENA[a]=s.charAt(a);
System.out.print((char)179+" "+CADENA[a]+" ");
}
//¨¨**********************************************
System.out.print("\n \n\t***CADENA INVERTIDA***\n\n");
////********se voltea el vector***********************************
for(int J=0; J<=s.length()-1; J++){
NUEVO[J]= CADENA[(s.length()-1)-J];
System.out.print((char)179+" "+NUEVO[J]+" ");
}
System.out.println("\n\n ");
/////////////////COMPARACION
contador=0;
x=0;
for(int j=0; j<=s.length()-1; j++)
{
if( NUEVO[j]==CADENA[j])
{
x=x+1;
}
if(x==s.length())
{
System.out.print("\n ES PALINDROMO \n");
break;
}
else
contador=contador+1;
if(contador==s.length())
{
System.out.println(" NO PALINDROMO!!!!");
}
}
System.out.print("\nDECEAS INTRODUCIR OTRA FRASE? SI/NO = ");
introducir = luis.readLine();
}while (introducir.equalsIgnoreCase("SI"));
}
}
Suscribirse a:
Entradas (Atom)