Java Implementation of “Inception”

Posted on August 14, 2010 at 21:14 Java

Inception

Feedback from friends, positively spoken and written (statuses), kept me wondering what the movie really was all about. I never set my eyes on it because the trailer didn’t intrigue nor enlighten me as a layman. But as it turns out, it’s way more nerve-wracking than you can think of.

After seeing a pseudocode post from my adviser and visiting the big screen, I knew I just had to make my own — a recursive one. To experience euphoria, I dug an implementation. What the program does is very simple. It asks for the levels of dream you wish to experience, and then prints out the time spent on each level. You’ll see…

Inception.java

void dream(int level) {
   if(level <= 0) {
      return;
   }

   try {
      System.out.print("Level " + level + ": ");
      long startTime = System.currentTimeMillis();
      Thread.sleep(1000*level);
      long endTime = System.currentTimeMillis();
      System.out.println((endTime-startTime) + " ms");
   } catch(InterruptedException ie) {}

   dream(level-1);
}

2 Comments

  1. gravatar.com deadrhonax
    February 22, 2011 at 00:52

    have you tried implementing this one?

    Reply

    • gravatar.com Nelson
      February 26, 2011 at 22:52

      Whad’you mean? That’s a working code.

Say What?

Name:
E-mail:
Website: (optional)

eXTReMe Tracker