Added 25 solutions
This commit is contained in:
@@ -4,50 +4,45 @@
|
||||
|
||||
import java.util.*;
|
||||
import java.security.*;
|
||||
|
||||
public class Solution {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) {
|
||||
DoNotTerminate.forbidExit();
|
||||
try {
|
||||
Scanner in = new Scanner(System.in);
|
||||
int n = in .nextInt();
|
||||
in.close();
|
||||
|
||||
/* Here are 3 ways to convert an int to a String */
|
||||
// String s = String.valueOf(n);
|
||||
// String s = Integer.toString(n);
|
||||
String s = "" + n;
|
||||
|
||||
DoNotTerminate.forbidExit();
|
||||
|
||||
try {
|
||||
Scanner in = new Scanner(System.in);
|
||||
int n = in .nextInt();
|
||||
in.close();
|
||||
//String s=???; Complete this line below
|
||||
|
||||
/* Here are 3 ways to convert an int to a String */
|
||||
// String s = String.valueOf(n);
|
||||
// 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.ExitTrappedException e) {
|
||||
System.out.println("Unsuccessful Termination!!");
|
||||
}
|
||||
}
|
||||
if (n == Integer.parseInt(s)) {
|
||||
System.out.println("Good job");
|
||||
} else {
|
||||
System.out.println("Wrong answer.");
|
||||
}
|
||||
} catch (DoNotTerminate.ExitTrappedException e) {
|
||||
System.out.println("Unsuccessful Termination!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//The following class will prevent you from terminating the code using exit(0)!
|
||||
// The following class will prevent you from terminating the code using exit(0)!
|
||||
class DoNotTerminate {
|
||||
|
||||
public static class ExitTrappedException extends SecurityException {
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
}
|
||||
|
||||
public static void forbidExit() {
|
||||
final SecurityManager securityManager = new SecurityManager() {
|
||||
@Override
|
||||
public void checkPermission(Permission permission) {
|
||||
if (permission.getName().contains("exitVM")) {
|
||||
throw new ExitTrappedException();
|
||||
public static class ExitTrappedException extends SecurityException {
|
||||
private static final long serialVersionUID = 1;
|
||||
}
|
||||
public static void forbidExit() {
|
||||
final SecurityManager securityManager = new SecurityManager() {
|
||||
@Override
|
||||
public void checkPermission(Permission permission) {
|
||||
if (permission.getName().contains("exitVM")) {
|
||||
throw new ExitTrappedException();
|
||||
}
|
||||
}
|
||||
};
|
||||
System.setSecurityManager(securityManager);
|
||||
}
|
||||
}
|
||||
};
|
||||
System.setSecurityManager(securityManager);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user