I am checking if number is between 1-10 using assert, but if I enter a number beyond 10 it still gives me the result rather than throwing an exception. What am I doing wrong?
import java.util.Scanner;
public class xina {
public static void main(String[] args) throws Exception {
System.out.println("enter any number");
Scanner input = new Scanner(System.in);
int num = input.nextInt();
assert ( num >= 0 && num <= 10 ) : "bad number: " + num;
System.out.println("You entered " + num);
}
}