class CharToCode {
public static void main(String[] args) {
char ch=’A’; // char ch=65;
int code = (int)ch; // ch to int type
System.out.printf(“%c=%d(%#X)%n”, ch, code, code);
char hch=’a’;// 97;
System.out.printf(“%c=%d(%#X)%n”, hch, (int)hch, (int)hch);
}
} // find the korean windows
class OverflowEx {
public static void main(String[] args) {
short sMin = -32768;
short sMax = 32767;
char cMin = 0;
char cMax = 65535;
System.out.println(“sMin = ” + sMin);
System.out.println(“sMin-1 = ” + (short)(sMin-1));
System.out.println(“sMax = ” + sMax);
System.out.println(“sMax+1 = ” + (short)(sMax+1));
System.out.println(“cMin = ” + (int)cMin);
System.out.println(“cMin-1 = ” + (int)–cMin);
System.out.println(“cMax = ” + (int)cMax);
System.out.println(“cMax+1 = ” + (int)++cMax);
}
}
class FloatEx1 {
public static void main(String[] args) {
float f = 9.12345678901234567890f;
float f2 = 1.2345678901234567890f;
double d = 9.12345678901234567890d;
System.out.printf(“ : 123456789012345678901234%n”);
System.out.printf(“f : %f%n”, f); // print ‘.’ below 6 space
System.out.printf(“f : %24.20f%n”, f);
System.out.printf(“f2 : %24.20f%n”, f2);
System.out.printf(“d : %24.20f%n”, d);
}
}
class CastingEx4 {
public static void main(String[] args) {
int i = 91234567; // 8 int
float f = (float)i; // int to float
int i2 = (int)f; // float to int
double d = (double)i; // int to double
int i3 = (int)d; // double to int
float f2 = 1.666f;
int i4 = (int)f2;
System.out.printf(“i=%d\n”, i);
System.out.printf(“f=%f i2=%d\n”, f, i2);
System.out.printf(“d=%f i3=%d\n”, d, i3);
System.out.printf(“(int)%f=%d\n”, f2, i4);
}
}