Monday, October 6, 2014

Generate Given Output #1

Leave a Comment


Question:

 
public class Test {
     
      public static void main(String[] args) {
            System.out.println("Ram");
      }

}


Modify the above code to get below output:

Hi
Ram
Bye

You shouldn’t modify main method.

Solution:



public class Test {
           
      static
      {
            System.out.println("Hi");
            main(null);
            System.out.println("Bye");
            System.exit(0);
      }
     
      public static void main(String[] args) {
            System.out.println("Ram");
      }

}

0 comments:

Post a Comment