This program compiles correctly, but doesn't run when I attempt to input values for width and height, instead giving me the error message "Exception in thread "main" java.lang.IllegalArgumentException: width and height must be positive". How do I correctly declare static variables that I define using Scanner outside the main method? (beginner programmer, sorry if this is obvious!)
public class Animation {
static int width;
static int height;
static double x0;
static double y0;
public static void main ( String[] args ) {
getInputs();
initStdDraw(width, height);
drawFace(x0, y0);
}
public static void initStdDraw(int width, int height) {
StdDraw.setCanvasSize(width, height);
StdDraw.setXscale(0, width);
StdDraw.setYscale(0, height);
StdDraw.rectangle(width/2, height/2, width/2, height/2);
}
public static void getInputs() {
Scanner console = new Scanner(System.in);
System.out.println("Please provide a canvas width and height: ");
int width = console.nextInt();
int height = console.nextInt();
System.out.println("Please provide a starting position: ");
double x0 = console.nextDouble();
double y0 = console.nextDouble();
x0 = console.nextDouble();instead ofdouble x0 = console.nextDouble();? (Same for the other 3 variables) As in, are you intending to assign the static variable or to define a new, unrelated local variable?