"HR자바 Java Int to String"의 두 판 사이의 차이

(새 문서: ==개요== ;{{subst:PAGENAME}} {{HR자바 헤더}} {{HR자바 Introduction}} |} ---- <source lang='java'> </source>)
 
잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(다른 사용자 한 명의 중간 판 2개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;HR자바 Java Int to String
;HR자바 Java Int to String
* https://www.hackerrank.com/challenges/java-int-to-string/problem


{{HR자바 헤더}}
{{HR자바 헤더}}
7번째 줄: 8번째 줄:


----
----
<source lang='java'>
 
</source>
<syntaxhighlight lang='java'>
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
</syntaxhighlight>
<syntaxhighlight lang='java'>
            //Write your code here
            String s = String.valueOf(n);
</syntaxhighlight>
<syntaxhighlight lang='java'>
            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);
    }
}
</syntaxhighlight>

2020년 11월 2일 (월) 02:51 기준 최신판

개요[ | ]

HR자바 Java Int to String
해커랭크 Java
# 문제 비고
HR자바 Introduction e
1 HR자바 Welcome to Java!
2 HR자바 Java Stdin and Stdout I
3 HR자바 Java If-Else
4 HR자바 Java Stdin and Stdout II
5 HR자바 Java Output Formatting
6 HR자바 Java Loops I
7 HR자바 Java Loops II
8 HR자바 Java Datatypes
9 HR자바 Java End-of-file
10 HR자바 Java Static Initializer Block
11 HR자바 Java Int to String
12 HR자바 Java Date and Time
13 HR자바 Java Currency Formatter

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 = String.valueOf(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);
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}