From 61b6f1e19e580c0207f146c9c1fdb8f7dda13743 Mon Sep 17 00:00:00 2001 From: Nathan-Abegaz <33362510+Nathan-Abegaz@users.noreply.github.com> Date: Sat, 1 Dec 2018 18:55:44 -0800 Subject: [PATCH] Added a section called "Casting". Details on how data types can be stored in other data types. (#23881) * Added a section called "Casting" * Reordered section, fixed typo --- guide/english/java/data-types/index.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/guide/english/java/data-types/index.md b/guide/english/java/data-types/index.md index c4c6ba54f9..ad7fd2e13a 100644 --- a/guide/english/java/data-types/index.md +++ b/guide/english/java/data-types/index.md @@ -110,7 +110,7 @@ double data type is a double-precision 64-bit [IEEE 754 floating point](http://s Default value: 0.0d. Example: double d1 = 123.400778; - + ## Character: We use this data type to store characters. This is not the same as the char in C/C++. Java uses a `UNICODE`, internationally accepted character set. Char in Java is 16­bits long while that in C/C++ is 8­bits. @@ -197,3 +197,19 @@ Output: ``` 10198442 ``` + +### Casting + +It is also important to note that it is possible to store different data types into one another. However, you would have to let the compiler know that you have acknowledge the possible loss of data by casting the variable. + +For example: +```java +double d = 1.23 + +int i = (int)d; +System.out.println(i); +``` +Output: +``` +1 +```