@@ -0,0 +1,2169 @@
+package java_problems.advanced;%0D%0A%0D%0Aimport java.io.*;%0D%0Aimport java.security.*;%0D%0A%0D%0A/*%0D%0A * Problem Statement: %0D%0A * You are given a class Solution and an inner class Inner.Private. The main%0D%0A * method of class Solution takes an integer num as input. The powerof2 in class%0D%0A * Inner.Private checks whether a number is a power of 2. You have to call the%0D%0A * method powerof2 of the class Inner.Private from the main method of the class%0D%0A * Solution.%0D%0A * %0D%0A * Constraints:%0D%0A * 1 %3C= num %3C= 230%0D%0A * %0D%0A * Sample Input: %0D%0A * 8%0D%0A * %0D%0A * Sample Output: %0D%0A * 8 is power of 2%0D%0A * An instance of class: Solution.Inner.Private has been created%0D%0A */%0D%0Apublic class CanYouAccess %7B%0D%0A%0D%0A%09public static void main(String%5B%5D args) throws Exception %7B%0D%0A%09%09Do_Not_Terminate.forbidExit();%0D%0A%0D%0A%09%09try %7B%0D%0A%09%09%09BufferedReader br = new BufferedReader(%0D%0A%09%09%09%09%09%09%09new InputStreamReader(System.in));%0D%0A%09%09%09int num = Integer.parseInt(br.readLine().trim());%0D%0A%09%09%09Object o;// Must be used to hold the reference of the instance of%0D%0A%09%09%09%09%09%09// the class Solution.Inner.Private%0D%0A%09%09%09o = new CanYouAccess.Inner().new Private();%0D%0A%0D%0A%09%09%09System.out.println(num + %22 is %22%0D%0A%09%09%09%09%09%09%09+ ((CanYouAccess.Inner.Private) o).powerof2(num));%0D%0A%0D%0A%09%09%09System.out.println(%22An instance of class: %22%0D%0A%09%09%09%09%09%09%09+ o.getClass().getCanonicalName()%0D%0A%09%09%09%09%09%09%09+ %22 has been created%22);%0D%0A%0D%0A%09%09%7D // end of try%0D%0A%0D%0A%09%09catch (Do_Not_Terminate.ExitTrappedException e) %7B%0D%0A%09%09%09System.out.println(%22Unsuccessful Termination!!%22);%0D%0A%09%09%7D%0D%0A%09%7D// end of main%0D%0A%0D%0A%09static class Inner %7B%0D%0A%09%09private class Private %7B%0D%0A%09%09%09private String powerof2(int num) %7B%0D%0A%09%09%09%09return ((num & num - 1) == 0) ? %22power of 2%22%0D%0A%09%09%09%09%09%09%09%09: %22not a power of 2%22;%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%7D// end of Inner%0D%0A%0D%0A%7D// end of Solution%0D%0A%0D%0Aclass Do_Not_Terminate %7B%0D%0A%0D%0A%09public static class ExitTrappedException extends SecurityException %7B%0D%0A%0D%0A%09%09private static final long serialVersionUID = 1L;%0D%0A%09%7D%0D%0A%0D%0A%09public static void forbidExit() %7B%0D%0A%09%09final SecurityManager securityManager = new SecurityManager() %7B%0D%0A%09%09%09@Override%0D%0A%09%09%09public void checkPermission(Permission permission) %7B%0D%0A%09%09%09%09if (permission.getName().contains(%22exitVM%22)) %7B%0D%0A%09%09%09%09%09throw new ExitTrappedException();%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D%0D%0A%09%09%7D;%0D%0A%09%09System.setSecurityManager(securityManager);%0D%0A%09%7D%0D%0A%7D%0D%0A

Add CanYouAccess