/***object to numeric primitive type***/
class objectToNumeric{
public static void main(String[] args){
Integer object=new Integer(4);
Double object2=new Double(10.4);
System.out.println(object);
float value=object.floatValue();
System.out.println("float:"+value);
int val=object.intValue();
System.out.println("int:"+val);
String str=new String("10");
int x=Integer.parseInt(str);
double d=Double.parseDouble(str);
System.out.println("double to integer:"+object2.intValue());
System.out.println("String to integer:"+x);
System.out.println("String to double:"+d);
System.out.println("Integer to string:"+object.toString());
}
}
The word "object" sounds like an instance of the "Object" class (java.lang.Object to be specific). You could possibly use another term other than "object". Otherwise, the given code in clear and precise. Keep up the good work!
ReplyDeleteAll the best!