Skip to content

Update JavaIntToString.java #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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+"";
}