Java Type Casting Example
Write a class, with main method, which declares floating point variables and observe the output
of dividing the floating point values by a 0, also observe the effect of assigning a high integer
value (8 digits and above) to a float and casting it back to int and printing.
Program:
public class q4
{
public static void main(String args[])
{
float f1 = 45, f2 = 0, f3;
f3 = f1 / f2;
System.out.println(f3); //infinity
f2 = 123456789;
System.out.println(f2); //1.23456792E8
}
}
of dividing the floating point values by a 0, also observe the effect of assigning a high integer
value (8 digits and above) to a float and casting it back to int and printing.
Program:
public class q4
{
public static void main(String args[])
{
float f1 = 45, f2 = 0, f3;
f3 = f1 / f2;
System.out.println(f3); //infinity
f2 = 123456789;
System.out.println(f2); //1.23456792E8
}
}
Comments
Post a Comment