
piedra papel o tijera
Publicado por Fatima (1 intervención) el 16/03/2020 22:35:34
Me pueden ayudar a saber el porque no funciona el do while, ya que necesito que para el programa cuando un jugador llega a las 3 partidas ganadas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package piedrapapelotijera;
import java.util.Scanner;
import static piedrapapelotijera.Operacion.Jugar;
/**
*
* @author ALUMNOS
*/
public class PiedraPapelOTijera {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Operacion o=new Operacion();
int j1, j2;
int g1=0, g2=0;
Scanner read=new Scanner(System.in);
do{
System.out.println("1=Piedra\n2=Papel\n3=Tijeras");
System.out.println("Jugador 1:\nIngresa tu jugada:");
j1=read.nextInt();
System.out.println("\n\n\n\n\n\n\n\n1=Piedra\n2=Papel\n3=Tijeras");
System.out.println("Jugador 2:\nIngresa tu jugada:");
j2=read.nextInt();
System.out.println("\n\n\n\n\n\n");
o.Jugar(j1, j2);
}while(g1<=3 || g2<=3);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package piedrapapelotijera;
/**
*
* @author ALUMNOS
*/
public class Operacion {
private static int e;
private static int g2;
private static int g1;
public static void Jugar(int j1, int j2 ){
if(j1==1 && j2==1)
{
e++;
System.out.println("Empate");
}else if(j1==1 && j2==2)
{
g2=g2+1;
System.out.println("Gana el jugador 2 "+g2);
}else if(j1==1 && j2==3)
{
g1++;
System.out.println("Gana el jugador 1"+g1);
}else if(j1==2 && j2==2)
{
e++;
System.out.println("Empate");
}else if(j1==2 && j2==1)
{
g1++;
System.out.println("Gana el jugador 1");
}else if(j1==2 && j2==3)
{
g2++;
System.out.println("Gana el jugador 2");
}else if(j1==3 && j2==3)
{
e++;
System.out.println("Empate");
}else if(j1==3 && j2==1)
{
g1++;
System.out.println("Gana el jugador 1");
}else if(j1==3 && j2==2)
{
g2++;
System.out.println("Gana el jugador 2");
}
}
}
Valora esta pregunta


0