//Implementing various type conversions in java
import java.io.*;
//creating the class type_conversion
class type_conversion
{
public static void main(String args[])
{
byte b=42;
float f=5.67f;
int i=257,k=97;
char c='a';
double d=323.142;
short s=1234;
long l=123456789;
System.out.println("
TYPE CONVERSION IN JAVA.");
System.out.println("
************************");
System.out.println("
Type conversion of integer to byte.");
b=(byte)i;
System.out.println("
i="+i+" and b="+b);
System.out.println("
Type conversion of integer to float.");
f=(float)i;
System.out.println("
i="+i+" and f="+f);
System.out.println("
Type conversion of integer to double.");
d=(double)i;
System.out.println("
i="+i+" and d="+d);
System.out.println("
Type conversion of double to integer.");
i=(int)d;
System.out.println("
d="+d+" and i="+i);
System.out.println("
Type conversion of double to byte.");
b=(byte)d;
System.out.println("
d="+d+" and b="+b);
System.out.println("
Type conversion of float to integer.");
i=(int)f;
System.out.println("
f="+f+" and i="+i);
System.out.println("
Type conversion of float to byte.");
b=(byte)f;
System.out.println("
f="+f+" and b="+b);
System.out.println("
Type conversion of long to short.");
s=(short)l;
System.out.println("
l="+l+" and s="+s);
System.out.println("
Type conversion of char to integer.");
i=(int)c;
System.out.println("
c="+c+" and i="+i);
System.out.println("
Type conversion of integer to character.");
c=(char)97;
System.out.println("
f=97"+" and c="+c);
System.out.println("
Type conversion of string to integer.");
String st=Integer.toString(k);
System.out.println("
k="+k+" and st="+st);
}
}