• Post Reply Bookmark Topic Watch Topic
  • New Topic

Assertion  RSS feed

 
Phal Ach
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. The following code is from Dan Chisholm's.
class A {
void m1(int i) {
int j = i % 3;
switch (j) {
case 0: System.out.print("0"); break;
case 1: System.out.print("1"); break;
default:
assert j == 2;
System.out.print(j);
}}
public static void main (String[] args) {
A a = new A();
for (int i=5; i >= -1; i--) {a.m1(i);}
}}

Which statements are true? Answer is :
1. With assertions enabled it prints 210210 followed by an AssertionError message
2. With assertions disabled it prints 210210-1

The problem here is, even if I enable assertion, I get answer 210210-1. Can anybody please tell me where am I going wrong? Thanks.
 
Bhavik patel
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Phalguni,

I tried your code on my IDE, both the options are correct.
 
Phal Ach
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhavik I am using command prompt and still it doesn't work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!