diff --git a/Doc/Sd1/languageFundamentals.xml b/Doc/Sd1/languageFundamentals.xml index 6d661c561c58d53e371cdf1589b54c0a61729189..31f0071d0ce1b9c56ec5f491be06b0f0c26f5a7a 100644 --- a/Doc/Sd1/languageFundamentals.xml +++ b/Doc/Sd1/languageFundamentals.xml @@ -1311,7 +1311,7 @@ int i = (int) d; // Explicit cast double to int</programlisting> </glossentry> <glossentry> - <glossterm>-4 + 1</glossterm> + <glossterm>-4 + 2</glossterm> <glossdef> <screen>-4 100 @@ -1340,8 +1340,8 @@ int i = (int) d; // Explicit cast double to int</programlisting> <glossterm>3 + 1</glossterm> <glossdef> - <screen> 1 001 - 3 +011 + <screen> 3 011 + 1 +001 -- ---- -4 100 Surprise! See comment below</screen> @@ -1438,13 +1438,13 @@ int i = (int) d; // Explicit cast double to int</programlisting> </tr> <tr> - <td><code>00000000000000000000000000000000</code></td> + <td><code>00000000_00000000_00000000_00000000</code></td> <td>0</td> </tr> <tr> - <td><code>01111111111111111111111111111111</code></td> + <td><code>01111111_11111111_11111111_11111111</code></td> <td><inlineequation> <m:math display="inline"> @@ -1453,7 +1453,7 @@ int i = (int) d; // Explicit cast double to int</programlisting> <m:mi>2</m:mi> <m:mrow> - <m:mi>16</m:mi> + <m:mi>32</m:mi> <m:mo>-</m:mo> @@ -1470,7 +1470,7 @@ int i = (int) d; // Explicit cast double to int</programlisting> </tr> <tr> - <td><code>10000000000000000000000000000000</code></td> + <td><code>10000000_00000000_00000000_00000000</code></td> <td><inlineequation> <m:math display="inline"> @@ -1481,7 +1481,7 @@ int i = (int) d; // Explicit cast double to int</programlisting> <m:mi>2</m:mi> <m:mrow> - <m:mi>16</m:mi> + <m:mi>32</m:mi> <m:mo>-</m:mo> @@ -1494,7 +1494,7 @@ int i = (int) d; // Explicit cast double to int</programlisting> </tr> <tr> - <td><code>11111111111111111111111111111111</code></td> + <td><code>11111111_11111111_11111111_11111111</code></td> <td>-1</td> </tr> @@ -4213,8 +4213,8 @@ System.out.println(2147483647 + 1L);</programlisting> <programlisting language="java">public static void main(String[] args) { final double a = 0.7; final double b = 0.9; - final double x = a + 0.1; // 0.9 - final double y = b - 0.1; // 0.9 + final double x = a + 0.1; // 0.8 + final double y = b - 0.1; // 0.8 System.out.println(x == y); }</programlisting> @@ -4659,66 +4659,20 @@ System.out.println("A circle of radius " + radius + " will cover an area of " + <para>Do we actually have to provide the value of pi (3.141592653589793) ourself?</para> - <programlisting language="java">double pi = 3.141592653589793; - -double radius = 2.3; // Computing a circle's area -System.out.println("A circle of radius " + radius + " will cover an area of " + - pi * radius * radius); - -pi = -4; // Woops, accidential redefinition - -radius = 1.8; - -System.out.println("A circle of radius " + radius + " will cover an area of " + - pi * radius * radius);</programlisting> - - <para>Modify the above code to avoid this type of error.</para> - <tip> - <itemizedlist> - <listitem> - <para>Consider <xref linkend="sd1_fig_final"/>.</para> - </listitem> - - <listitem> - <para>Read the <quote>Constants</quote> section of <xref - linkend="bib_Kurniawan2015"/>. As an aside also read the - nearby section concerning naming conventions for constant - variable as well.</para> - </listitem> - </itemizedlist> + <para>Consider the standard <link + xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#PI">Math + library</link>.</para> </tip> </question> <answer> - <para>The solution is straightforward. We add the <code - xlink:href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.12.4">final</code> - modifier to the definition of our variable <code>pi</code>. In - addition we use capital letters <code>PI</code> reflecting the - naming convention for constants:</para> + <para>The solution is straightforward using <link + xlink:href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#PI">Math.PI</link>:</para> - <programlisting language="java" linenumbering="numbered">final double PI = 3.141592653589793; -double radius = 2.3; // Computing a circle's area + <programlisting language="java" linenumbering="numbered">double radius = 2.3; // Computing a circle's area System.out.println("A circle of radius " + radius + " will cover an area of " + - PI * radius * radius); - -PI = -4; - -radius = 1.8; - -System.out.println("A circle of radius " + radius + " will cover an area of " + - PI * radius * radius);</programlisting> - - <para>Now our flawed assignment at line 6 will be flagged as a - compile time error:</para> - - <para><computeroutput>Cannot assign a value to final variable - 'PI'</computeroutput></para> - - <para>As a rule of thumb: Whenever you intend a variable not to - change after an initial assignment use <code - xlink:href="https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.12.4">final</code> - declaring it to remain constant.</para> + Math.PI * radius * radius);</programlisting> </answer> </qandaentry> </qandadiv> diff --git a/Doc/Sd1/statements.xml b/Doc/Sd1/statements.xml index 9205b26d95c03074f8072a911a8aa5a654de6e51..2100051002ccbcd855a44d15c0bcec3bc954c196 100644 --- a/Doc/Sd1/statements.xml +++ b/Doc/Sd1/statements.xml @@ -393,7 +393,7 @@ int main(int argc, char **args) { if(...)</code> branch construct but nevertheless tries to implement the logic being shown in <xref linkend="sd1_fig_ifElse"/>. Please help by just using - <code>if(...)</code> (having no <code>else</code> branch) + <code>if(...)</code> (having no <code>else if(...)</code> branch) statements!</para> <tip> diff --git a/Doc/Tdoc/general.xml b/Doc/Tdoc/general.xml index 7c973dd41f63f78f9dea53f24356e39d7024a855..3e209c12eb5f4f86839683292a816cf287842d34 100644 --- a/Doc/Tdoc/general.xml +++ b/Doc/Tdoc/general.xml @@ -2631,8 +2631,8 @@ See <xref linkend="intro"/> ...</programlisting> <chapter xml:id="<emphasis role="bold">intro</emphasis>"> <title>Introduction</title> <para>...</para> - </chapter xml:id="<emphasis role="bold">work</emphasis>"> - <chapter> + </chapter> + <chapter xml:id="<emphasis role="bold">work</emphasis>"> <title>Working with objects</title> <para>...</para> </chapter> @@ -2682,11 +2682,11 @@ See <xref linkend="intro"/> ...</programlisting> <tr> <td><programlisting language="xml"><book ...> <title>XML for Newbies</title> - <chapter xml:id="<emphasis role="bold">intro</emphasis>"> + <chapter xml:id="<emphasis role="red">intro</emphasis>"> <title>Introduction</title> <para>...</para> </chapter> - <chapter> + <chapter xml:id="<emphasis role="red">work</emphasis>"> <title>Working with objects</title> <para>...</para> </chapter> @@ -2706,12 +2706,12 @@ See <xref linkend="intro"/> ...</programlisting> <itemizedlist> <listitem> <para><emphasis - role="bold">intro</emphasis>.html</para> + role="red">intro</emphasis>.html</para> </listitem> <listitem> <para><emphasis - role="bold">work</emphasis>.html</para> + role="red">work</emphasis>.html</para> </listitem> </itemizedlist> </listitem>