- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
Latest commit
50 lines (42 loc) · 1.22 KB
/
Copy pathsolution.java
File metadata and controls
50 lines (42 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// github.com/Utkarsh299-tech
importjava.util.*;
importjava.security.*;
publicclassSolution {
publicstaticvoidmain(String[] args) {
DoNotTerminate.forbidExit();
try {
Scannerin = newScanner(System.in);
intn = in .nextInt();
in.close();
//String s=???; Complete this line below
Strings = String.valueOf(n);
// Other two methods of conversion:
// String s = Integer.toString(n);
// String s = "" + n;
if (n == Integer.parseInt(s)) {
System.out.println("Good job");
} else {
System.out.println("Wrong answer.");
}
} catch (DoNotTerminate.ExitTrappedExceptione) {
System.out.println("Unsuccessful Termination!!");
}
}
}
//The following class will prevent you from terminating the code using exit(0)!
classDoNotTerminate {
publicstaticclassExitTrappedExceptionextendsSecurityException {
privatestaticfinallongserialVersionUID = 1;
}
publicstaticvoidforbidExit() {
finalSecurityManagersecurityManager = newSecurityManager() {
@Override
publicvoidcheckPermission(Permissionpermission) {
if (permission.getName().contains("exitVM")) {
thrownewExitTrappedException();
}
}
};
System.setSecurityManager(securityManager);
}
}