首页 > 代码库 > java实例 把一个整形n强制转化为字符串
java实例 把一个整形n强制转化为字符串
n的范围是-100--100
如果成功转换,则打印Good job ,若不成功则打印Wrong answer;
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 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); } }
java实例 把一个整形n强制转化为字符串
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。