-1
I’m trying to make a program like "lottery", locked in a mistake there on if
. If you can help me, follow the code:
package praticando;
import java.util.Random;
import java.util.Scanner;
public class JogoNumeros {
public static void main(String[] args) {
Random aleatorio = new Random();
int valor = aleatorio.nextInt(10) + 1;
Scanner N = new Scanner (System.in);
System.out.println("Faça sua aposta digitando um número de 1 até 10: ");
int aposta = N.nextInt();
System.out.println("Número sorteado|---> " + valor);
if N = valor {
System.out.print(" $$$$ PARABÉNS, você ganhou na loteria!!! $$$$$");
}else{
System.out.println("Não foi desta vez, continue apostando!");
}
}
}
Hello, Thiago, you are using the wrong operator. For Assignment we use the same (=), for comparison we used (==), try and see if this is it. Logo in line if N = value tries if N == value ;
– Marcus Italo
Take a look over how to ask questions
– absentia
Hello Marcus Italo, you are right. I modified but not yet rolled.
– Thiago
@Marcusitalus
N
is aScanner
, it makes no sense to compare it with aint
. What must be done isif (valor == aposta)
– hkotsubo
I modified it, but it’s not running yet.
– Thiago
Yes, it worked. Thank you. *
– Thiago
But the with a yellow bulb with exclamation. Thank you friend.
– Thiago