float f = 0;
f = br.readFloat();

解决方案 »

  1.   

    因为你这样float f=br.readFloat()有可能会使得f得不到初始化(尽管你确定它肯定可以得到复制),故报错
      

  2.   

    DataInputStream br=new DataInputStream(System.in);
    float f = Float.parseFloat(br.readLine());
    System.out.println(f);
      

  3.   

    为什么以下可用,但是我的不能用呢?
    DataInputStream br=new DataInputStream(System.in);
    float f = Float.parseFloat(br.readLine());
    System.out.println(f);
    这和br.readFloat的功能是一样的呀!
    为什么我的方法会导致变量不能初始化?
      

  4.   

    可能由于parsefloat方法会使f变量确定被初始化
    所以编译通过
      

  5.   

    public static float parseFloat(String s)
                            throws NumberFormatException
    Returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Double.
      

  6.   

    以下是此方法介绍
    parseFloat public static float parseFloat(String s)
                
    throws NumberFormatException 
    Returns a new float 
    initialized to the value 
    represented by the specified String, as performed by the valueOf method of class Double.
    Parameters:s - the string to be parsed.
    Returns:the float value represented by the string argument.
    Throws:NumberFormatException - if the string does not contain a parsable float.
    例子:Note: If the value of gg is null, trim() will throw a NullPointerException. If you don't use trim(), make sure there's no trailing white space. For JDK 1.2.x or better: 
    From String gg To long n: 
    try {
      n = Long.parseLong(gg.trim());
    }
    catch (NumberFormatException e) {
      ...
    }    
      

  7.   

    照这么说,那么readFloat不是就没有用了吗?
      

  8.   

    奇怪了
    我用JB7编译,通过不报错
    yuanxulong198010 (虫子) 
    你试过了吗?
      

  9.   

    readFloat public float readFloat()
                    throws IOException Reads four input bytes and returns a float value. 
    It does this by first constructing an int value in exactly the manner of the readInt method, then converting this int value to a float in exactly the manner of the method Float.intBitsToFloat
    This method is suitable for reading bytes written by the writeFloat method of interface DataOutput.
    Returns:the float value read.
    Throws:EOFException - if this stream reaches the end before reading all the bytes.
    IOException - if an I/O error occurs
      

  10.   

    假如我连续输入了几个整数,那么readInt是不是也不能用,是不是也会提示变量没有初始化
      

  11.   

    我用的是jdk1.1.8,我的代码不能通过,真是奇怪呀!
      

  12.   

    下载新版的jdk八或者装jb6或77好一点八readInt public int readInt()
                throws IOException 
    Reads four input bytes and returns an int value. Let a be the first byte read, b be the second byte, c be the third byte, and d be the fourth byte. 
    The value returned is:  
     (((a & 0xff) << 24) | ((b & 0xff) << 16) |
      ((c & 0xff) << 8) | (d & 0xff))
      This method is suitable for reading bytes written by the writeInt method of interface DataOutput.
    Returns:the int value read.
    Throws:EOFException - if this stream reaches the end before reading all the bytes.
    IOException - if an I/O error occurs.