Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import java.util.*;
  2. import java.security.*;
  3. public class Solution {
  4. public static void main(String[] args) {
  5.  
  6. DoNotTerminate.forbidExit();
  7.  
  8. try {
  9. Scanner in = new Scanner(System.in);
  10. int n = in .nextInt();
  11. in.close();
  12. //String s=???; Complete this line below
  13.  
  14. String s = Integer.toString(n);
  15.  
  16.  
  17.  
  18. if (n == Integer.parseInt(s)) {
  19. System.out.println("Good job");
  20. } else {
  21. System.out.println("Wrong answer.");
  22. }
  23. } catch (DoNotTerminate.ExitTrappedException e) {
  24. System.out.println("Unsuccessful Termination!!");
  25. }
  26. }
  27. }
  28.  
  29. //The following class will prevent you from terminating the code using exit(0)!
  30. class DoNotTerminate {
  31.  
  32. public static class ExitTrappedException extends SecurityException {
  33.  
  34. private static final long serialVersionUID = 1;
  35. }
  36.  
  37. public static void forbidExit() {
  38. final SecurityManager securityManager = new SecurityManager() {
  39. @Override
  40. public void checkPermission(Permission permission) {
  41. if (permission.getName().contains("exitVM")) {
  42. throw new ExitTrappedException();
  43. }
  44. }
  45. };
  46. System.setSecurityManager(securityManager);
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement