Skip to content

Instantly share code, notes, and snippets.

@JoseLuisGardunoArrieta
Forked from eduardojesus12/Ejercicio4.java
Last active November 29, 2024 19:39
Show Gist options
  • Save JoseLuisGardunoArrieta/9e9b9e5459214bf8e86bae7c1ebb9744 to your computer and use it in GitHub Desktop.
Save JoseLuisGardunoArrieta/9e9b9e5459214bf8e86bae7c1ebb9744 to your computer and use it in GitHub Desktop.
Trabajar con código de otros 4
package ejerciciosFer4;
import java.util.Scanner; //importo scanner
public class Ejercicio4 {
@SuppressWarnings("resource") // agrego esto desde return
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Turno del jugador 1 (introduzca piedra, papel o tijeras): ");
String j1 = s.nextLine();
System.out.print("Turno del jugador 2 (introduzca piedra, papel o tijeras): ");
/* Scanner s2 = new Scanner(); */
String j2 = s.nextLine();
if (j1.equals(j2)) {
System.out.println("Empate");
} else {
int g = 2;
switch(j1) {
case "piedra":
if (j2.equals("tijeras")) {
g = 1;
}
break; // añado mas breaks para completar el codigo
case "papel":
if (j2.equals("piedra")) {
g = 1;
}
break;
case "tijeras":
if (j2.equals("papel")) {
g = 1;
}
break;
default:
System.out.println("No es una entrada valida");
return;
}
System.out.println("Gana el jugador " + g);
}
s.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment