How to add assertions ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kbanerjee2002
    New Member
    • Aug 2006
    • 1

    #1

    How to add assertions ?

    class FooTes {
    int i = 105;
    public void go() {
    if(i<= 100)
    {
    System.out.prin tln("Cho Cho");
    assert(i==100)
    {
    throw new RuntimeExceptio n("Assertion must be enabled!");

    }
    }
    else
    {
    System.out.prin tln("Mo Mo");
    }
    }
    }

    class FooTesDrive {
    public static void main(String args[])
    {
    FooTes foo = new FooTes();
    foo.go();
    }
    }

    Code is not working.
    Best Regards
    K Banerjee
    :o
  • heat84
    New Member
    • Nov 2007
    • 118

    #2
    Did you enable assertions when you complied.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by kbanerjee2002
      class FooTes {
      int i = 105;
      public void go() {
      if(i<= 100)
      {
      System.out.prin tln("Cho Cho");
      assert(i==100)
      {
      throw new RuntimeExceptio n("Assertion must be enabled!");

      }
      }
      else
      {
      System.out.prin tln("Mo Mo");
      }
      }
      }

      class FooTesDrive {
      public static void main(String args[])
      {
      FooTes foo = new FooTes();
      foo.go();
      }
      }

      Code is not working.
      Best Regards
      K Banerjee
      :o
      1.) Please use code tags when posting code
      2.) What do you mean by " Code is not working"? Is there a compilation error? What's the error? Or is it a runtime exception?
      You get answers quicker if you don't make it difficult for others to understand your question.

      Comment

      Working...