Skip to content

Commit e141814

Browse files
authored
Merge pull request #278 from habibasorour/issue_260_liting
Issue 260 fixed: Add listing in 4.6
2 parents 41a8752 + 09e5d99 commit e141814

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

source/ch4_conditionals.ptx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,10 @@ Java also provides the ternary operator <c>condition ? valueIfTrue : valueIfFals
463463
</table>
464464

465465
<p>
466-
Using this operator can make code shorter and more readable in cases where a simple conditional assignment is needed. See the following as an example where we see the same logic implemented in two different ways.
466+
Using this operator can make code shorter and more readable in cases where a simple conditional assignment is needed. <xref ref="java-ternary" text="type-global"/> shows an example where we see the same logic implemented in two different ways.
467467
</p>
468-
<program xml:id="java-ternary" interactive="activecode" language ="java">
468+
<listing xml:id="java-ternary">
469+
<program interactive="activecode" language ="java">
469470
<code>
470471
public class Ternary {
471472
public static void main(String[] args) {
@@ -489,9 +490,10 @@ public class Ternary {
489490
}
490491
</code>
491492
</program>
493+
</listing>
492494

493495
<p>
494-
In this example we are using this ternary operator to assign a value to <c>a</c> based on whether <c>a</c> is even or odd. If <c>a</c> is even, it will be squared; if odd, it will be instead be calculated as <c>3 * x - 1</c>. This is a concise way to write conditional assignments in Java. However, you might want to use it sparingly, as it can make code less readable if overused or used with complex expressions.
496+
In <xref ref="java-ternary" text="type-global"/>, we are using this ternary operator to assign a value to <c>a</c> based on whether <c>a</c> is even or odd. If <c>a</c> is even, it will be squared; if odd, it will be instead be calculated as <c>3 * x - 1</c>. This is a concise way to write conditional assignments in Java. However, you might want to use it sparingly, as it can make code less readable if overused or used with complex expressions.
495497
</p>
496498

497499

0 commit comments

Comments
 (0)