I
ITrishGuru
Hi there,
My java lecturer has given us an assignment related to casting and
type conversion etc.
One of the conversions he wan't is convert "Hello" to a float.
I suspect this is a trick question on his part as "Hello" is not a
parsible value.
This is the code I have:
//Convert String object "s" to a Float object
//then convert Float object to float value
try { System.out.println("String is "+s+" float is
"+Float.valueOf(s).floatValue());
}
catch (NumberFormatException NFE)
{ System.out.println("NumberFormatException: "+ NFE.getMessage()+
" The input string does not contain a parsable number"); }
I emailed the guy but he says just to use your own judgement.
I looked at the API for the wrapper classes etc and I think a
conversion of this type is almost impossible.
Any ideas welcome.
My java lecturer has given us an assignment related to casting and
type conversion etc.
One of the conversions he wan't is convert "Hello" to a float.
I suspect this is a trick question on his part as "Hello" is not a
parsible value.
This is the code I have:
//Convert String object "s" to a Float object
//then convert Float object to float value
try { System.out.println("String is "+s+" float is
"+Float.valueOf(s).floatValue());
}
catch (NumberFormatException NFE)
{ System.out.println("NumberFormatException: "+ NFE.getMessage()+
" The input string does not contain a parsable number"); }
I emailed the guy but he says just to use your own judgement.
I looked at the API for the wrapper classes etc and I think a
conversion of this type is almost impossible.
Any ideas welcome.