07/05/2006, 15:46
|
| Colaborador | | Fecha de Ingreso: julio-2005
Mensajes: 4.352
Antigüedad: 19 años, 6 meses Puntos: 24 | |
Me gusto el porblema que planteaste y lo resolvi mas o menos
Cualquier duda, pregunte
Código:
public class test {
public static void main(String [] args) {
Clave key = new Clave("666","444","111");
if(key.validarClave())
System.out.println("Es correcto");
else
System.out.println("Es incorrecto");
}
}
public class Clave {
String subKey1;
String subKey2;
String subKey3;
public Clave(String subClave1, String subClave2, String subClave3){
subKey1 = subClave1;
subKey2 = subClave2;
subKey3 = subClave3;
}
public boolean validarClave(){
if (validarSubStr1() && validarSubStr2() && validarSubStr3())
return true;
else
return false;
}
private boolean validarSubStr1() {
boolean ret = true;
for (int i=0;i<subKey1.length();i++)
if(Integer.parseInt(subKey1.substring(i,i+1))<=5)
ret = false;
if(subKey1.length()== 3 && ret)
return true;
else
return false;
}
private boolean validarSubStr2() {
boolean ret = true;
for (int i=0;i<subKey2.length();i++)
if(Integer.parseInt(subKey2.substring(i,i+1))>=5)
ret = false;
if(subKey2.length()== 3 && ret)
return true;
else
return false;
}
private boolean validarSubStr3() {
boolean ret = true;
for(int i=0;i<subKey3.length()-1;i++)
if(subKey3.toCharArray()[i]!=subKey3.toCharArray()[i+1])
ret = false;
if(subKey3.length()== 3 && ret)
return true;
else
return false;
}
}
|