import java.util.Scanner; public class Esercizio5switch { public static void main(String[] args) { // Uso queste variabili in modo da non dover ripetere queste // scritte tutte le volte. final String VINCE = "Vince giocatore"; final String PARI = "Pari"; final String F_VS_C = "forbice taglia carta"; final String S_VS_F = "sasso spessa forbici"; final String C_VS_S = "carta avvolge sasso"; Scanner tastiera = new Scanner(System.in); System.out.print("Inserire mossa del giocatore 1: "); String g1 = tastiera.next().toLowerCase(); System.out.print("Inserire mossa del giocatore 2: "); String g2 = tastiera.next().toLowerCase(); // interessante per l'uso degli switch annidati switch (g1) { case "c": switch (g2) { case "c": System.out.println(PARI); break; case "f": System.out.println(VINCE + " 2: " + F_VS_C); break; default: System.out.println(VINCE + " 1: " + C_VS_S); } break; case "f": switch (g2) { case "c": System.out.println(VINCE + " 1: " + F_VS_C); break; case "f": System.out.println(PARI); break; default: System.out.println(VINCE + " 2: " + S_VS_F); } break; default: switch (g2) { case "c": System.out.println(VINCE + " 2: " + C_VS_S); break; case "f": System.out.println(VINCE + " 1 " + S_VS_F); break; default: System.out.println(PARI); break; } } tastiera.close(); } }