码迷,mamicode.com
首页 > 编程语言 > 详细

java实例 把一个整形n强制转化为字符串

时间:2017-03-09 23:13:28      阅读:370      评论:0      收藏:0      [点我收藏+]

标签:uid   contain   div   mission   can   port   long   following   let   

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强制转化为字符串

标签:uid   contain   div   mission   can   port   long   following   let   

原文地址:http://www.cnblogs.com/Angella/p/6528258.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!