dimanche 2 janvier 2022

Java how do i pass in the random int into my switch java

I just cant figure out why im getting a null pointer exception?? th program gets to the first case and says i is not pointing to anything??

public String computerChoice()
{   
    int i = ran.nextInt(4);
    String str;
    switch (i){
    case 1:  
        str = "paper";
    case 2: 
        str = "rock";
    case 3: 
        str = "scissors";
    default:
        str = "not valid";   
    }
    return str;
} 



Aucun commentaire:

Enregistrer un commentaire