Page 76 - CA_Blue( J )_Class9
P. 76
Program 19 Write a program to demonstrate the type conversion of float to int.
1 class float_to_int
2 {
3 public static void main (String args[])
4 {
5 float x = 7.36f;
6 int y;
7 y = (int )x;
8 System.out.println("Float value: " + x);
9 System.out.println("Integer Value: " +y);
10 }
11 }
You will get the following output:
Program 20 Write a program to demonstrate the type conversion in a calculation.
1 class Average
2 {
3 public static void main(String args[])
4
5 {
6 int m1 = 55;
7 int m2 = 70;
8 int m3 = 80;
9 double average;
10 average = (double)(m1+m2+m3)/3;
11 int i = (int)average;
74 Touchpad Computer Applications-IX

