Java Program that perform type conversion like int to byte, double to int, double to byte etc.( other possible types)
Program
class conversion
{
public static void main(String[] args)
{
byte b;
int i=123;
double d=121.212;
System.out.println("\nConversion of int to byte");
b=(byte)i;
System.out.println("i= " + i + " b= " + b);
System.out.println("\nConversion of double to int");
i=(int)d;
System.out.println("d= " + d +" i= "+i);
System.out.println("\nConversion of double to byte");
b=(byte)d;
System.out.println("d= " + d + " b= " + b);
//The type promotion rules.....
byte b1=11;
char c1='a';
short s1=256;
int i1=4000;
float f1=1.24f;
double d1=0.123;
double result=(f1*b1)+(i1/c1)-(d1*s1);
System.out.println((f1*b1)+ " + " + (i1/c1) + " - " + (d1*s1));
System.out.println("Result-->" + result);
}
}
No comments:
Post a Comment