Skip to content

Commit 311797d

Browse files
authored
Merge pull request #82 from logananglin98/Issue#56Fix
Fixed pre tag formatting and line breaks
2 parents 6f3b153 + f1f0dcd commit 311797d

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

source/ch_4_javadatatypes.ptx

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,20 @@ public class TempConv {
212212
For Python programmers, the following error is likely to be even more common. Suppose we forgot the declaration for <c>cel</c> and instead left line 6 blank. What would happen when we type <c>javac TempConv.java</c> on the command line?
213213
</p>
214214

215-
<pre>TempConv.java:13: cannot find symbol symbol : variable cel location: class TempConv cel = (fahr - 32) * 5.0/9.0; ^ TempConv.java:14: cannot find symbol symbol : variable cel location: class TempConv System.out.println("The temperature in C is: " + cel); ^ 2 errors</pre>
215+
<pre>
216+
TempConv.java:13: cannot find symbol
217+
symbol : variable cel
218+
location: class TempConv
219+
cel = (fahr - 32) * 5.0/9.0;
220+
^
221+
TempConv.java:14: cannot find symbol
222+
symbol : variable cel
223+
location: class TempConv
224+
System.out.println("The temperature in C is: " + cel);
225+
^
226+
2 errors
227+
</pre>
228+
216229
<p>
217230
When you see the first kind of error, where the symbol is on the left side of the equals sign, it usually means that you have not declared the variable. If you have ever tried to use a Python variable that you have not initialized the second error message will be familiar to you. The difference here is that we see the message before we ever try to test our program. More common error messages are discussed in the section <xref ref="common-mistakes-id1"/>.
218231
</p>
@@ -522,7 +535,11 @@ public class Histo {
522535
Technically, you don&#x2019;t <em>have</em> to declare what is going to be in an array list. The compiler will allow you to leave the <c>&lt;``*Type*</c>&gt;`` off the declaration. If you don&#x2019;t tell Java what kind of object is going to be on the list Java will give you a warning message like this:
523536
</p>
524537

525-
<pre>Note: Histo.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.</pre>
538+
<pre>
539+
Note: Histo.java uses unchecked or unsafe operations.
540+
Note: Recompile with -Xlint:unchecked for details.
541+
</pre>
542+
526543
<p>
527544
Without the <c>&lt;Integer&gt;</c> part of the declaration Java simply assumes that <em>any</em> object can be on the list. However, without resorting to an ugly notation called casting, you cannot do anything with the objects on a list like this! So, if you forget you will surely see more errors later in your code. (Try it and see what you get)
528545
</p>
@@ -531,7 +548,14 @@ public class Histo {
531548
Lines 13&#x2014;20 are required to open the file. Why so many lines to open a file in Java? The additional code mainly comes from the fact that Java forces you to reckon with the possibility that the file you want to open is not going to be there. If you attempt to open a file that is not there you will get an error. A try/catch construct allows us to try things that are risky, and gracefully recover from an error if one occurs. The following example shows the general structure of a try/catch block.
532549
</p>
533550

534-
<pre>try { Put some risky code in here, like opening a file } catch (Exception e) { If an error happens in the try block an exception is thrown. We will catch that exception here! }</pre>
551+
<pre>
552+
try {
553+
Put some risky code in here, like opening a file
554+
} catch (Exception e) {
555+
If an error happens in the try block an exception is thrown. We will catch that exception here!
556+
}
557+
</pre>
558+
535559
<p>
536560
Notice that in line 16 we are catching an <c>IOException</c>. In fact, we will see later that we can have multiple catch blocks to catch different types of exceptions. If we want to be lazy and catch any old exception we can catch an <c>Exception</c> which is the parent of all exceptions. However, catching <c>Exception</c> is a terrible practice, since you may inadvertently catch exceptions you do not intend to, making it harder to identify bugs in your program.
537561
</p>

source/ch_6_loopsanditeration.ptx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,24 @@ public class DefiniteLoopExample {
4242
Recall that the <c>range</c> function provides you with a wide variety of options for controlling the value of the loop variable.
4343
</p>
4444

45-
<pre>range(stop)
46-
range(start,stop)
47-
range(start,stop,step)</pre>
45+
<pre>
46+
range(stop)
47+
range(start,stop)
48+
range(start,stop,step)
49+
</pre>
4850

4951
<p>
5052
The Java <c>for</c> loop is really analogous to the last option giving you explicit control over the starting, stopping, and stepping in the three clauses inside the parenthesis.
5153
You can think of it this way:
5254
</p>
5355

54-
<pre>for (start clause; stop clause; step clause) {
55-
statement1
56-
statement2
57-
...
58-
}</pre>
56+
<pre>
57+
for (start clause; stop clause; step clause) {
58+
statement1
59+
statement2
60+
...
61+
}
62+
</pre>
5963

6064
<p>
6165
If you want to start at 100, stop at 0 and count backward by 5, the Python loop would be written as:

0 commit comments

Comments
 (0)