728x90
반응형
해커랭크 - https://www.hackerrank.com/
Prepare > Java > Introduction > Java Int to String
HackerRank
HackerRank is the market-leading technical assessment and remote interview solution for hiring developers. Learn how to hire technical talent from anywhere!
www.hackerrank.com
정수 n이 주어지면 이를 문자열로 변환해야 합니다.
코드가 n을 문자열 s로 성공적으로 변환하면 코드는 "Good job"을 인쇄합니다. 그렇지 않으면 "Wrong answer"이 인쇄됩니다.
n은 -100에서 100(포함) 사이의 범위일 수 있습니다.
Sample Input :
100
Sample Output :
Good job
Code :
import java.util.*;
import java.security.*;
public class Solution {
public static void main(String[] args) {
DoNotTerminate.forbidExit();
try {
Scanner in = new Scanner(System.in);
int n = in .nextInt();
in.close();
//String s=???; Complete this line below
//Write your code here
String s = Integer.toString(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!!");
}
}
}
//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);
}
}
개인 공부를 위한 포스팅입니다.
모든 번역, 코드는 완벽하지 않을 수 있습니다.
728x90
반응형
'> 개발-IT-인터넷 > > JAVA' 카테고리의 다른 글
[해커랭크(HackerRank) JAVA 풀이] - Java Strings Introduction (0) | 2021.08.31 |
---|---|
[해커랭크(HackerRank) JAVA 풀이] - Java Currency Formatter (0) | 2021.08.27 |
[해커랭크(HackerRank) JAVA 풀이] - Java Static Initializer Block (0) | 2021.08.27 |
[해커랭크(HackerRank) JAVA 풀이] - Java End-of-file (0) | 2021.08.06 |
[해커랭크(HackerRank) JAVA 풀이] - Java Datatypes (1) | 2021.08.04 |