Kod: Zaznacz cały
//: c03:CastingNumbers.java
// From 'Thinking in Java, 2nd ed.' by Bruce Eckel
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
// What happens when you cast a float
// or double to an integral value?
public class CastingNumbers {
public static void main(String[] args) {
double above = 0.7, below = 1.4;
System.out.println("above: " + above);
System.out.println("below: " + below);
System.out.println("(int)above: " + (int) above);
System.out.println("(int)below: " + (int) below);
System.out.println("(char)('a' + above): " + (char) ('a' + above));
System.out.println("(char)('a' + below): " + (char) ('a' + below));
}
} // /:~
Kod: Zaznacz cały
above: 0.7
below: 1.4
(int)above: 0
(int)below: 1
(char)('a' + above): a
(char)('a' + below): b