domingo, 21 de agosto de 2011
picas Y FIJAS
public class PicasYFijas {
private int n1;
private int n2;
private int n3;
public PicasYFijas (int n1, int n2, int n3){
this.n1 = n1;
this.n2 = n2;
this.n3 = n3;
}
public String getPicasYFijas(int nd1, int nd2, int nd3){
int p = 0;
int f = 0;
if ((n1 == nd1) && (n2 == nd2) && (n3 == nd3)){
return ("3 FIJAS");
}
else {
if (n1 == nd1){
f = f + 1;
}
if (n2 == nd2){
f = f + 1;
}
if (n3 == nd3){
f = f + 1;
}
if ((n1 == nd2) || (n1 == nd3)){
p = p + 1;
}
if ((n2 == nd1) || (n2 == nd3)){
p = p + 1;
}
if ((n3 == nd1) || (n3 == nd2)){
p = p + 1;
}
}
return ("Picas " + p + " Fijas " + f);
}
}
INICIO;
import java.io.*;
public class Inicio {
public static void main(String[]args)throws IOException {
BufferedReader lectura = new BufferedReader(new InputStreamReader(System.in));
int n1;
int n2;
int n3;
PicasYFijas pF = new PicasYFijas (3 , 2, 9);
System.out.println("Ingrese numero 1: ");
n1 = Integer.parseInt(lectura.readLine());
System.out.println("Ingrese numero 2: ");
n2 = Integer.parseInt(lectura.readLine());
System.out.println("Ingrese numero 3: ");
n3 = Integer.parseInt(lectura.readLine());
while (!pF.getPicasYFijas(n1, n2, n3).equals("3 FIJAS")){
System.out.println("Ingrese numero 1: ");
n1 = Integer.parseInt(lectura.readLine());
System.out.println("Ingrese numero 2: ");
n2 = Integer.parseInt(lectura.readLine());
System.out.println("Ingrese numero 3: ");
n3 = Integer.parseInt(lectura.readLine());
System.out.println(pF.getPicasYFijas(n1, n2, n3));
}
}
}
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario