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.
以下是此方法介绍 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) { ... }
照这么说,那么readFloat不是就没有用了吗?
奇怪了 我用JB7编译,通过不报错 yuanxulong198010 (虫子) 你试过了吗?
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
假如我连续输入了几个整数,那么readInt是不是也不能用,是不是也会提示变量没有初始化
我用的是jdk1.1.8,我的代码不能通过,真是奇怪呀!
下载新版的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.
float f = Float.parseFloat(br.readLine());
System.out.println(f);
DataInputStream br=new DataInputStream(System.in);
float f = Float.parseFloat(br.readLine());
System.out.println(f);
这和br.readFloat的功能是一样的呀!
为什么我的方法会导致变量不能初始化?
所以编译通过
throws NumberFormatException
Returns a new float initialized to the value represented by the specified String, as performed by the valueOf method of class Double.
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) {
...
}
我用JB7编译,通过不报错
yuanxulong198010 (虫子)
你试过了吗?
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
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.