- Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathjava-int-to-string.java
More file actions
Latest commit
58 lines (47 loc) · 1.46 KB
/
Copy pathjava-int-to-string.java
File metadata and controls
58 lines (47 loc) · 1.46 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
51
52
53
54
55
56
57
58
// Java > Introduction > Java Int to String
// Convert an integer to a string.
//
// https://www.hackerrank.com/challenges/java-int-to-string/problem
// challenge id: 14556
//
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
// (skeliton_head) ----------------------------------------------------------------------
//Write your code here
Strings = Integer.toString(n);
// (skeliton_tail) ----------------------------------------------------------------------
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);
}
}