public class TypeConvert {
public static void main(String[] args) {
fromInt();
fromFloat();
fromDouble();
fromChar();
toOther();
}
public static void fromInt()
{
Integer intvar=1;
String Strint;
Strint=String.valueOf(intvar);
System.out.println(Strint);
}
public static void fromFloat()
{
Float floatvar=9.99999f;
String Strfloat;
Strfloat=String.valueOf(floatvar);
System.out.println(Strfloat);
}
public static void fromDouble()
{
Double doublevar=9.999999999999999;
String Strdouble;
Strdouble=String.valueOf(doublevar);
System.out.println(Strdouble);
}
public static void fromChar()
{
char charvar='a';
String Strchar;
Strchar=String.valueOf(charvar);
System.out.println(Strchar);
}
public static void toOther()
{
System.out.println("Convert to other type.\n Begin");
String intStr="100";
String fltStr="10.333f";
String longStr="9999999999";
String doubleStr="9999999.9";
String str="1";
Integer _int=Integer.parseInt(intStr);
System.out.println(_int);
Float _float=Float.parseFloat(fltStr);
System.out.println(_float);
Long _long=Long.parseLong(longStr);
System.out.println(_long);
Double _double=Double.parseDouble(doubleStr);
System.out.println(_double);
Byte _byte=Byte.parseByte(str);
System.out.println(_byte);
Short _short=Short.parseShort(str);
System.out.println(_short);
Boolean _boolean=Boolean.parseBoolean(str);
System.out.println(_boolean);
System.out.println("End");
}
}