Embed presentation
Download to read offline
![//Ques. 7 WAP to demonstrate type conversions ( int to byte, double to int,
double to byte ).
class conversion
{
public static void main(String arr[])
{
byte b;
inti = 257;
double d = 323.142;
System.out.println(" n Conversion of int to byte: ");
b= (byte) i;
System.out.print(" i = "+i+ " b = "+b);
System.out.println("n n Conversion of double to int: ");
i= (int) d;
System.out.print(" d = "+d+ " i = "+i);
System.out.println("n n Conversion of double to byte: ");
b= (byte) d;
System.out.println(" d = "+d+ " b = "+b);
}
}](https://image.slidesharecdn.com/conversion-131127074935-phpapp02/85/Conversion-of-data-types-in-java-1-320.jpg)


This document demonstrates type conversions in Java by writing a program that converts an int to a byte, a double to an int, and a double to a byte. It defines a main method that declares the variables, performs the conversions by casting the values, and prints the original and converted values to show the results of the conversions.
![//Ques. 7 WAP to demonstrate type conversions ( int to byte, double to int,
double to byte ).
class conversion
{
public static void main(String arr[])
{
byte b;
inti = 257;
double d = 323.142;
System.out.println(" n Conversion of int to byte: ");
b= (byte) i;
System.out.print(" i = "+i+ " b = "+b);
System.out.println("n n Conversion of double to int: ");
i= (int) d;
System.out.print(" d = "+d+ " i = "+i);
System.out.println("n n Conversion of double to byte: ");
b= (byte) d;
System.out.println(" d = "+d+ " b = "+b);
}
}](https://image.slidesharecdn.com/conversion-131127074935-phpapp02/85/Conversion-of-data-types-in-java-1-320.jpg)
