import java.util.Scanner;
class AssertDemo {
public static void main(String[] args) {
Scanner scanner = new Scanner( System.in );
int value = scanner.nextInt();
assert ( value >= 0 && value <= 10 ) : "bad number: " + value;
System.out.println(value);
}
}
=================================================================
D:\javaworkspace\javaspecifiedlanguage>java -ea AssertDemo
99
Exception in thread "main" java.lang.AssertionError: bad number: 99
at AssertDemo.main(AssertDemo.java:7)
class AssertDemo {
public static void main(String[] args) {
Scanner scanner = new Scanner( System.in );
int value = scanner.nextInt();
assert ( value >= 0 && value <= 10 ) : "bad number: " + value;
System.out.println(value);
}
}
=================================================================
D:\javaworkspace\javaspecifiedlanguage>java -ea AssertDemo
99
Exception in thread "main" java.lang.AssertionError: bad number: 99
at AssertDemo.main(AssertDemo.java:7)