Hello, good greetings, I would like to ask you one thing
they sent me to do a program that randomly picks up an option of the machine and a user option
I was doing it with import java.util.Random;
but I realized that this is only applicable with numbers and when I get to the comparison time I want to compare the word of the machine = wordMachine = word user I can not do it anymore
I can not compare a int
with a string
this is what I have
package juego;
import java.util.Random;
import java.util.Scanner;
public class juego {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
Random ga = new Random();
menu ( sc, ga);
}
static void ramdom ( Scanner sc, Random ga) {
System.out.println("Escoje entre Piedra / Papel / Tijeras ");
String eleccion;
eleccion = sc.nextLine();
int numeroAleatorio = ga.nextInt(3);
System.out.println(numeroAleatorio);
int resultado;
resultado = numeroAleatorio;
switch (resultado) {
case 0:
System.out.println("Piedra");
break;
case 1:
System.out.println("Papel");
break;
case 2:
System.out.println("Tijeras");
break;
}
If I can not explain myself well basically when choosing a random number I want it to be a word