import java.util.concurrent.Semaphore;

public class SemJava {

   private final Semaphore sem;

   public SemJava( int InitValue ) {
      sem = new Semaphore( InitValue );

   }

   void P() {

      try {
         sem.acquire();
      } catch (InterruptedException e ) {
         System.out.println( e );
         System.exit( 2 );
      }

   }

   void V() {

      sem.release();

   }

   void Wait() {

      P();

   }

   void Signal() {

      V();

   }

}

