The following program is not working as I want. The assert() function is not working while I'm entering a number which is out of range 0-10. Whereas, according to my book, it is working like that:
Output:
Enter a number between 0 and 10: 50
Exception in thread "main" java.lang.AssertionError: bad number: 50
at AssertionTest.main(AssertTest.java:15)
But I cannot see the error message above after compiling the program on eclipse and netbeans. I just see that:
Output:
Enter a number between 0 and 10: 50
You entered 50
What is the problem? Why the function assert is not working?
import java.util.Scanner; public class Assertion { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter a number between 0 and 10: "); int number = input.nextInt(); assert(number >= 0 && number <= 10) : "bad number: " + number; // assert, "bildir" demektir. System.out.printf("You entered %d\n",number); } }