- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaIntToString.java
More file actions
Latest commit
46 lines (39 loc) · 1.11 KB
/
Copy pathJavaIntToString.java
File metadata and controls
46 lines (39 loc) · 1.11 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
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 = Integer.toString(n);
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);
}
}