This question already has an answer here:
I wrote this piece of code, which is supposed to print out a statement which says "everything is perfect" but unfortunately is gives an error which says "The local variable number may not have been initialized"
import java.util.Scanner; import java.util.Random;
class apples { public static void main(String args[]) {
Random dice = new Random();
int number;
for(int i=1; i<=10; i++) {
number = dice.nextInt(6)+1;
System.out.println(number);
}
if(number > 0) {
System.out.println("everything is perfect");
}
}
}
Aucun commentaire:
Enregistrer un commentaire