Commit ec5bbb7d by Jose Figueredo

segunda tarea

parents
import java.util.*;
public class VacasToros {
private String numero;
private char a[];
private int vacas;
private int toros;
public VacasToros(String n){
this.numero=n;
for(int i=0;i<4;i++)
{
a[i] =n.charAt(i);
}
verificar(a);
}
public boolean verificar(char a[]){
int bandera=0;
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(a[i]==a[j] && i!=j)
{
bandera=1;
j=4;
i=10;
}
}
}
if(bandera==1)
return false;
return true;
}
public boolean verificar(String c){
char d[]= new char[4];
for(int i=0;i<4;i++)
{
d[i] =c.charAt(i);
}
int bandera=0;
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(d[i]==d[j] && i!=j)
{
bandera=1;
j=4;
i=10;
}
}
}
if(bandera==1)
return false;
return true;
}
public void comparar(String n){
char b[]= new char[4];
for(int i=0;i<4;i++)
{
b[i] =n.charAt(i);
}
for(int i=0;i<4;i++)
{
if(a[i]==b[i])
{
toros++;
}
else{
for(int j=0;j<4;j++)
{
if (a[i]==b[j])
{
vacas++;
}
}
}
}
System.out.println("VACAS :"+vacas+" TOROS: "+toros);
}
public static void main(String[] args) {
VacasToros juego = new VacasToros("1521");
Scanner teclado= new Scanner(System.in);
String a= teclado.nextLine();
String b= teclado.nextLine();
while(juego.verificar(a) && juego.verificar(b))
{
juego.comparar(b);
// no pude terminar por tiempo
}
}
}
compilar javac VacasToros.java
ejecutar java VacasToros
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment