String TestStr="8";int testInt=Integer.parseInt(TestStr, 2);
   
int temp=Integer.valueOf(TestStr, 2).intValue();上面两个 都会报错....
 求解!

解决方案 »

  1.   

    抛出的异常为: throw NumberFormatException.forInputString(s);
      

  2.   

    Integer.parseInt用法错误int testInt=Integer.parseInt(TestStr);
    Integer.valueOf用法错用int temp=Integer.valueOf(TestStr).intValue();
    你加个2想代表什么?
      

  3.   

    Parses the string argument as a signed integer in the radix specified by the second argument. The characters in the string must all be digits of the specified radix (as determined by whether java.lang.Character.digit(char, int) returns a nonnegative value), except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value. The resulting integer value is returned. 
    An exception of type NumberFormatException is thrown if any of the following situations occurs: The first argument is null or is a string of length zero. The radix is either smaller than java.lang.Character.MIN_RADIX or larger than java.lang.Character.MAX_RADIX. 
    Any character of the string is not a digit of the specified radix, except that the first character may be a minus sign '-' ('\u002D') provided that the string is longer than length 1. 
    The value represented by the string is not a value of type int. 
    Examples:  parseInt("0", 10) returns 0
     parseInt("473", 10) returns 473
     parseInt("-0", 10) returns 0
     parseInt("-FF", 16) returns -255
     parseInt("1100110", 2) returns 102
     parseInt("2147483647", 10) returns 2147483647
     parseInt("-2147483648", 10) returns -2147483648
     parseInt("2147483648", 10) throws a NumberFormatException
     parseInt("99", 8) throws a NumberFormatException
     parseInt("Kona", 10) throws a NumberFormatException
     parseInt("Kona", 27) returns 411787
     
    Parameters:
    s the String containing the integer representation to be parsed
    radix the radix to be used while parsing s.
    Returns:
    the integer represented by the string argument in the specified radix.
    Throws:
    NumberFormatException - if the String does not contain a parsable int.
      

  4.   


    其实吧 我是想把它转成二进制的1000,然后转为一个String类型 就变成字符串"1000"
      

  5.   

    我晕,把8转为2进制用Integer.parseInt?和Integer.valueOf,你知道这2个干嘛的不?十进制转成十六进制:Integer.toHexString(int i)十进制转成八进制Integer.toOctalString(int i)十进制转成二进制Integer.toBinaryString(int i)十六进制转成十进制Integer.valueOf("FFFF",16).toString()八进制转成十进制Integer.valueOf("876",8).toString()二进制转十进制Integer.valueOf("0101",2).toString()有什么方法可以直接将2,8,16进制直接转换为10进制的吗?java.lang.Integer类parseInt(String s, int radix)使用第二个参数指定的基数,将字符串参数解析为有符号的整数。examples from jdk:parseInt("0", 10) returns 0parseInt("473", 10) returns 473parseInt("-0", 10) returns 0parseInt("-FF", 16) returns -255parseInt("1100110", 2) returns 102parseInt("2147483647", 10) returns 2147483647parseInt("-2147483648", 10) returns -2147483648parseInt("2147483648", 10) throws a NumberFormatExceptionparseInt("99",throws a NumberFormatExceptionparseInt("Kona", 10) throws a NumberFormatExceptionparseInt("Kona", 27) returns 411787进制转换如何写(二,八,十六)不用算法Integer.toBinaryStringInteger.toOctalStringInteger.toHexString例二public class Test{public static void main(String args[]){int i=100;String binStr=Integer.toBinaryString(i);String otcStr=Integer.toOctalString(i);String hexStr=Integer.toHexString(i);System.out.println(binStr);}例二public class TestStringFormat {public static void main(String[] args) {if (args.length == 0) {System.out.println("usage: java TestStringFormat <a number>");System.exit(0);}Integer factor = Integer.valueOf(args[0]);String s;s = String.format("%d", factor);System.out.println(s);s = String.format("%x", factor);System.out.println(s);s = String.format("%o", factor);System.out.println(s);}}其他方法:Integer.toHexString(你的10进制数);例如String temp = Integer.toHexString(75);输出temp就为 4b//输入一个10进制数字并把它转换成16进制import java.io.*;public class toHex{public static void main(String[]args){int input;//存放输入数据//创建输入字符串的实例BufferedReader strin=new BufferedReader(new InputStreamReader(System.in));System.out.println("请输入一个的整数:");String x=null;try{x=strin.readLine();}catch(IOException ex){ex.printStackTrace();}input=Integer.parseInt(x);System.out.println ("你输入的数字是:"+input);//输出从键盘接收到的数字System.out.println ("它的16进制是:"+Integer.toHexString(input));//用toHexString把10进制转换成16进制}}很想问一句,你是程序员?
      

  6.   

    String TestStr="8";int testInt=Integer.parseInt(TestStr, 2);--->应该是这样子才对吧(parseInt("1100110", 2) returns 102 ):String TestStr = "1000" ;
    int testInt=Integer.parseInt(TestStr, 2);
    结果为testInt = 8 ;
      

  7.   


    我回答一句 我是做C#的,第三天写JAVA代码,请多见谅!
      

  8.   

    int i=8;
    String testInt=Integer.toBinaryString(i);  
    System.out.println(testInt);
    转成二进制的1000,然后转为一个String类型 就变成字符串"1000"
    好吧,这应该是你想要的
      

  9.   


    我是想把 
    String TestStr="8"; 转成二进制的 1000
    然后在转为String 类型 再赋值给别的变量~
      

  10.   

    你想要的我已经写给你了
    String TestStr="8";
    int testInt=Integer.parseInt(TestStr);
    String testInt=Integer.toBinaryString(testInt);   
    System.out.println(testInt);
      

  11.   

    Integer i = 9 ;
    String str = i.toBinaryString(i) ;
    System.out.println(str) ;  //1001