Formatting experiments

This commit is contained in:
Bruce Eckel 2017-01-23 08:18:49 -08:00
parent 0870429756
commit 04039c7b6a
12 changed files with 66 additions and 34 deletions

View File

@ -14,12 +14,16 @@ public class AlphabeticSearch {
show(sa);
int index = Arrays.binarySearch(sa,
sa[10], String.CASE_INSENSITIVE_ORDER);
System.out.println( "Index: "+ index + "\n"+ sa[index]);
System.out.println(
"Index: "+ index + "\n"+ sa[index]);
}
}
/* Output:
[anmkkyh, bhmupju, btpenpc, cjwzmmr, cuxszgv,
eloztdv, ewcippc, ezdeklu, fcjpthl, fqmlgsh, gmeinne, hyoubzl, jbvlgwc, jlxpqds,
ljlbynx, mvducuj, qgekgly, skddcat, taprwxz, uybypgp, vjsszkn, vniyapk, vqqakbm,
vwodhcf, ydpulcq, ygpoalk, yskvett, zehpfmm, zofmmvm, zrxmclh] Index: 10 gmeinne
eloztdv, ewcippc, ezdeklu, fcjpthl,
fqmlgsh, gmeinne, hyoubzl, jbvlgwc, jlxpqds,
ljlbynx, mvducuj, qgekgly, skddcat,
taprwxz, uybypgp, vjsszkn, vniyapk, vqqakbm,
vwodhcf, ydpulcq, ygpoalk, yskvett,
zehpfmm, zofmmvm, zrxmclh] Index: 10 gmeinne
*/

View File

@ -32,6 +32,6 @@ public class ApplesAndOrangesWithoutGenerics {
___[ Error Output ]___
Exception in thread "main" java.lang.ClassCastException:
Orange cannot be cast to Apple
at ApplesAndOrangesWithoutGenerics.main(ApplesAndOr
at ApplesAndOrangesWithoutGenerics.main(ApplesAndOr
angesWithoutGenerics.java:23)
*/

View File

@ -27,8 +27,8 @@ public class ListIteration {
}
}
/* Output:
Rat, 1, 0; Manx, 2, 1; Cymric, 3, 2; Mutt, 4, 3; Pug, 5, 4;
Cymric, 6, 5; Pug, 7, 6; Manx, 8, 7;
Rat, 1, 0; Manx, 2, 1; Cymric, 3, 2; Mutt, 4, 3;
Pug, 5, 4; Cymric, 6, 5; Pug, 7, 6; Manx, 8, 7;
7 6 5 4 3 2 1 0
[Rat, Manx, Cymric, Mutt, Pug, Cymric, Pug, Manx]
[Rat, Manx, Cymric, Cymric, Rat, EgyptianMau, Hamster,

View File

@ -44,6 +44,6 @@ IF SHE WEIGHS THE SAME AS A DUCK, SHE'S MADE OF WOOD
Using Processor Downcase
if she weighs the same as a duck, she's made of wood
Using Processor Splitter
[If, she, weighs, the, same, as, a, duck,, she's, made, of,
wood]
[If, she, weighs, the, same, as, a, duck,, she's, made,
of, wood]
*/

View File

@ -70,10 +70,14 @@ public class DelayQueueDemo {
}
}
/* Output:
[128] Task 12 [429] Task 6 [551] Task 13 [555] Task 2 [693] Task 3 [809] Task 15
[961] Task 5 [1258] Task 1 [1258] Task 20 [1520] Task 19 [1861] Task 4 [1998] T
ask 17 [2200] Task 8 [2207] Task 10 [2288] Task 11 [2522] Task 9 [2589] Task 14
[2861] Task 18 [2868] Task 7 [3278] Task 16 (0:4000)
[128] Task 12 [429] Task 6 [551] Task 13
[555] Task 2 [693] Task 3 [809] Task 15
[961] Task 5 [1258] Task 1 [1258] Task 20
[1520] Task 19 [1861] Task 4 [1998] T
ask 17 [2200] Task 8 [2207] Task 10 [2288]
Task 11 [2522] Task 9 [2589] Task 14
[2861] Task 18 [2868] Task 7 [3278]
Task 16 (0:4000)
(1:1258)
(2:555)
(3:693)

View File

@ -16,7 +16,8 @@ public class ChatterClient implements Runnable {
public ChatterClient(InetAddress hostAddress) {
this.hostAddress = hostAddress;
System.out.println("ChatterClient #" + id + " starting");
System.out.println(
"ChatterClient #" + id + " starting");
}
public void sendAndEcho(String msg) {
try (
@ -42,6 +43,7 @@ public class ChatterClient implements Runnable {
@Override
public void run() {
for(int i = 0; i <= 5; i++)
sendAndEcho("Client #" + id + ", message #" + i);
sendAndEcho(
"Client #" + id + ", message #" + i);
}
}

View File

@ -35,6 +35,8 @@ public class ChatterServer implements Runnable {
dp.getAddress(), dp.getPort());
socket.send(echo);
}
} catch(IOException e) { throw new RuntimeException(e); }
} catch(IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -31,7 +31,8 @@ Specification
user.dir=C:\Users\Bruce\Documents\GitHub\on-ja...
java.runtime.version=1.8.0_102-b14
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Program Files (x86)\Java\jdk1.8.0_...
java.endorsed.dirs=C:\Program Files
(x86)\Java\jdk1.8.0_...
os.arch=x86
java.io.tmpdir=C:\Users\Bruce\AppData\Local\Temp\
...

View File

@ -30,7 +30,7 @@ public class URShift {
/* Output:
11111111111111111111111111111111
1111111111111111111111
11111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111
11111
111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111

View File

@ -3,13 +3,17 @@
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
public class DerivedSpaceShip extends SpaceShipControls {
public class
DerivedSpaceShip extends SpaceShipControls {
private String name;
public DerivedSpaceShip(String name) { this.name = name; }
public DerivedSpaceShip(String name) {
this.name = name;
}
@Override
public String toString() { return name; }
public static void main(String[] args) {
DerivedSpaceShip protector = new DerivedSpaceShip("NSEA Protector");
DerivedSpaceShip protector =
new DerivedSpaceShip("NSEA Protector");
protector.forward(100);
}
}

View File

@ -93,15 +93,19 @@ IllegalStateException
null
NullPointerException
Robert
IndexOutOfBoundsException: index (6) must be less than size (6)
IndexOutOfBoundsException: index (6) must be less
than size (6)
Bob
IndexOutOfBoundsException: index (6) must be less than size (3)
IndexOutOfBoundsException: index (6) must be less
than size (3)
null
NullPointerException
Robert
Success
Bob
IndexOutOfBoundsException: index (6) must not be greater than size (3)
IndexOutOfBoundsException: index (6)
must not be greater
than size (3)
null
NullPointerException
Hieronymus
@ -109,11 +113,15 @@ Success
Hieronymus
Success
Hieronymus
IndexOutOfBoundsException: end index (11) must not be greater than size (10)
IndexOutOfBoundsException: end index (11)
must not be greater
than size (10)
Hieronymus
IndexOutOfBoundsException: start index (-1) must not be negative
IndexOutOfBoundsException: start index (-1)
must not be negative
Hieronymus
IndexOutOfBoundsException: end index (6) must not be less than start index (7)
IndexOutOfBoundsException: end index (6)
must not be less than start index (7)
null
NullPointerException
*/

View File

@ -92,7 +92,8 @@ public class CircularQueueTest {
testNullPut
put() null item
testCircularity
in = 0, out = 0, full() = true, empty() = false, CircularQueue =
in = 0, out = 0, full() = true, empty() = false,
CircularQueue =
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
0
1
@ -104,10 +105,12 @@ in = 0, out = 0, full() = true, empty() = false, CircularQueue =
7
8
9
in = 0, out = 0, full() = false, empty() = true, CircularQueue =
in = 0, out = 0, full() = false, empty() = true,
CircularQueue =
[null, null, null, null, null, null, null, null, null,
null]
in = 0, out = 0, full() = true, empty() = false, CircularQueue =
in = 0, out = 0, full() = true, empty() = false,
CircularQueue =
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
10
11
@ -119,16 +122,19 @@ in = 0, out = 0, full() = true, empty() = false, CircularQueue =
17
18
19
in = 0, out = 0, full() = false, empty() = true, CircularQueue =
in = 0, out = 0, full() = false, empty() = true,
CircularQueue =
[null, null, null, null, null, null, null, null, null,
null]
testFull
in = 5, out = 0, full() = false, empty() = false, CircularQueue =
in = 5, out = 0, full() = false, empty() = false,
CircularQueue =
[0, 1, 2, 3, 4, null, null, null, null, null]
0
1
put() into full CircularQueue
in = 2, out = 2, full() = true, empty() = false, CircularQueue =
in = 2, out = 2, full() = true, empty() = false,
CircularQueue =
[10, 11, 2, 3, 4, 5, 6, 7, 8, 9]
testEmpty
0
@ -137,7 +143,8 @@ testEmpty
3
4
get() from empty CircularQueue
in = 5, out = 5, full() = false, empty() = true, CircularQueue =
in = 5, out = 5, full() = false, empty() = true,
CircularQueue =
[null, null, null, null, null, null, null, null, null,
null]
*/