Issue
package oui;
import java.util.Scanner;
public class dicecalc {
private static Scanner kb;
public static void main(String args[]) {
//;-; i need words to add in
int numGuess;
System.out.println("Enter the number the numer the dice will roll: ");
numGuess = kb.nextInt();
int dice1=(int)(Math.random()*6+1);
int dice2=(int)(Math.random()*6+1);
int sum = dice1 + dice2;
System.out.print("Roll: total = " + sum);
{
if (sum != numGuess) {
System.out.println("Sorry with a " + sum + " You LOSE :(");
} else {
System.out.println("Woah!!! With a " + sum + " You WIN!!!!!!!");
}
}
}
}
Solution
private static Scanner kb;
is not initialized. There is no need to make this variable global, so move it inside the main()
method as follows:
Scanner kb = new Scanner(System.in);
Answered By - hfontanez
Answer Checked By - Robin (JavaFixing Admin)