黑马程序员技术交流社区

标题: 字符串转成整数,没你想象的那么简单 [打印本页]

作者: 陈宁    时间: 2014-12-8 23:49
标题: 字符串转成整数,没你想象的那么简单
接收一个用户输入的字符串,假如为16进制的数。
String s ="3cef";
请用int 来接收此数,或把此数转为10进制,即
int a=0X3cef或
int a=15599;
折腾了一个多小时 ,还是没有结果。请高手解决一下。
作者: 水竹    时间: 2014-12-8 23:57
字符串转成整数,就是这么简单!
  1. public class SoEasy
  2. {
  3.         public static void main(String[] args){
  4.                 String s ="3cef";
  5.                 int a=Integer.parseInt(s,16);
  6.                 System.out.println(a);
  7.         }
  8. }
复制代码


作者: jacoblx    时间: 2014-12-8 23:58
public class Demo {
  public static void main(String[] args) {
    String str = "3cef";
    int num = Integer.parseInt(str, 16);
    System.out.println(num);
  }
}

作者: 有陷阱快跑丶    时间: 2014-12-9 13:22
加上进制数在Integer.parseInt (String s ,16 )




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2