Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,52 @@
*/
package com.javaaid.hackerrank.solutions.languages.java.introduction;

/**
* @author Kanahaiya Gupta
*
*/
public class JavaIntToString {
int n; //already decalared
int n; //already decalaredimport java.util.*;
import java.security.*;

public class Main {
public static void main(String[] args) {

DoNotTerminate.forbidExit();

try {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.close();
String s = String.valueOf(n); // Convert integer n to string s

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)!
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();
}
}
};
System.setSecurityManager(securityManager);
}
}

String s=n+"";
}