
import javax.swing.JOptionPane;
public class Evaluador1 {
private int pos = 0;
private char cad[];
private int t;
public void estableceCad(String c){
cad = c.toCharArray();
t = c.length();
}
public boolean evalua(){
if(cad[pos]=='a'){
if(evaluaA()){
if(evaluaB() && pos == t)
return true;
return false;
}
return false;
}
else if(cad[pos] == 'b'){
pos++;
if(evaluaB())
return true;
return false;
}
return false;
}
public boolean evaluaA(){
while(pos<t && cad[pos]=='a')
pos++;
if(pos == t)
return false;
return true;
}
public boolean evaluaB(){
if(pos < t && cad[pos]=='b'){
while(pos<t && cad[pos]=='b')
pos++;
if(pos==t)
return true;
return false;
}
return false;
}
public static void main(String[] args) {
Evaluador1 e = new Evaluador1();
try{
for( ; ; ){
e.pos = 0;
e.estableceCad(JOptionPane.showInputDialog(null,"Ingrese la cadena a verificar","Entrada Abelo003",JOptionPane.PLAIN_MESSAGE));
if(e.evalua())
JOptionPane.showMessageDialog(null,"Cadena CORRECTA","OK!!!! Abelo003",JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null,"Cadena INCORRECTA","MAL!!!!Abelo003",JOptionPane.WARNING_MESSAGE);
}
}
catch(NullPointerException ui){}
}
}
//Gracias por sus comentarios...
//saludos de Jimbo
t3 v4 4 r3g4ñ4r l4 pr0f44!!
ResponderEliminarN0 h4i p2s ti0,
ResponderEliminarsigue mi blog----->>> http://lolamett.blogspot.com/2011/05/para-los-aburridos.html
ResponderEliminarESTA MUY BUENO EL PROGRAMA!!! GRAX X EL DATO, X MI PARTE LO TOMARE EN CUENTA.
*Lola Mett*
ok muchacha, seguire subiendo cosas relacionadas, espero sigas visitandome
ResponderEliminar