Q:

Java scanner won't accept negative integer values and only works with positive values

I'm struggling to understand why my program will only work when I only input positive integer values. I think it's something to do with the scanner, but more information on it is helpful.
import java.util.Scanner;

class integerThree {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);

    int x = 0;
    int y = 0;
    int z = 0;
    int smallest = 0;
    int largest = 0;

    System.out.print("Enter first integer: ");
    x = input.nextInt();

    System.out.print("Enter second integer: ");
    y = input.nextInt();

    System.out.print("Enter third integer: ");
    z = input.nextInt();

    smallest = x;

    if (y < smallest) {
        smallest = y;
    }

    if (z < smallest) {
        smallest = z;

    largest = x;

    if (y > largest) {
        largest = y;
    }

    if (z > largest) {
        largest = z;
    }

    System.out.printf("%d+%d+%d=%d%n", x, y, z, (x+y+z));
    System.out.printf("%s=(%d+%d+%d)/3=%d%n", "Integer Avg", x, y, z, (x + y + z) / 3);
    System.out.printf("%d*%d*%d=%d%n", x, y, z, (x * y * z));
    System.out.printf("Of %d, %d, and %d %d is the smallest.%n", x, y, z, smallest);
    System.out.printf("Of %d, %d, and %d %d is the largest.%n", x, y, z, largest);
    }
  }
}

The output is supposed to add three numbers, find the average of three numbers, multiply them, find the lowest, and finally, find the highest number. Is there a way to make it so that negatives won't cause an error?

A:

It appears you're missing a closing brace '}' after your second If statement. So your program will only work if the final input value Z is the smallest. Other than this program seems to work for me.
So change your second if to this:
if (z < smallest) {
    smallest = z;
}

You'll also need to remove one of your final 3 closing braces.

