Page 75 - CA_Blue( J )_Class9
P. 75
21 st
Some More Programs Century #Coding & Computational Thinking
Skills
Program 17 Write a program to demonstrate calculations using explicit conversion.
1 import java.util.*;
2 class explicite_calculation
3 {
4 public static void main()
5 {
6 double centigrade;
7 int fahrenheit;
8 centigrade=35.8;
9 fahrenheit=(int)(centigrade/5.0*9+32);
10 System.out.println("Centigrade: "+centigrade);
11 System.out.println("Fahrenheit: "+fahrenheit);
12 }
13 }
You will get the following output:
Boolean data type is not compatible with any other primitive data types. So, it cannot be converted to any other
type or vice versa neither by implicit nor explicit data type conversion. Let us understand with an example:
Program 18 Example of Boolean data conversion.
1 class conversion
2 {
3 public static void main()
4 {
5 char c='A';
6 boolean b=c; // error - incompatible types:char cannot be converted to
boolean
7 System.out.println(b);
8 }
9 }
It returns an error “incompatible types: char cannot be converted to boolean”
Values and Types 73

