From 173383a98e0aef3801232b3b2392402039624694 Mon Sep 17 00:00:00 2001 From: manasser99 <84741910+manasser99@users.noreply.github.com> Date: Sun, 20 Jun 2021 18:07:20 -0400 Subject: [PATCH 1/4] Add files via upload --- .../chapter10/practice/BinaryReader.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/com/codefortomorrow/intermediate/chapter10/practice/BinaryReader.java diff --git a/src/com/codefortomorrow/intermediate/chapter10/practice/BinaryReader.java b/src/com/codefortomorrow/intermediate/chapter10/practice/BinaryReader.java new file mode 100644 index 0000000..ac6db9e --- /dev/null +++ b/src/com/codefortomorrow/intermediate/chapter10/practice/BinaryReader.java @@ -0,0 +1,28 @@ +/* + Create a program called BinaryReader in which a 4 x 4 + array of booleans is created. Have the computer loop + through the array, printing a 0 if the current element is + set to false and a 1 if it set to true. + + Example Array: + { + {true, false, false, true}, + {false, true, true, true}, + {true, true, false, true}, + {true, false, false, false} + } + + Example Output: + 1001 + 0111 + 1101 + 1000 +*/ + +public class BinaryReader +{ + public static void main(String[] args) + { + + } +} \ No newline at end of file From bc46ce0cf2a47ca4df71f4b3d1e7916713d2f17b Mon Sep 17 00:00:00 2001 From: manasser99 <84741910+manasser99@users.noreply.github.com> Date: Sun, 20 Jun 2021 18:08:13 -0400 Subject: [PATCH 2/4] Update BinaryReader.java --- .../intermediate/chapter10/practice/BinaryReader.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/com/codefortomorrow/intermediate/chapter10/practice/BinaryReader.java b/src/com/codefortomorrow/intermediate/chapter10/practice/BinaryReader.java index ac6db9e..a572e7c 100644 --- a/src/com/codefortomorrow/intermediate/chapter10/practice/BinaryReader.java +++ b/src/com/codefortomorrow/intermediate/chapter10/practice/BinaryReader.java @@ -1,3 +1,5 @@ +package com.codefortomorrow.intermediate.chapter10.practice; + /* Create a program called BinaryReader in which a 4 x 4 array of booleans is created. Have the computer loop @@ -25,4 +27,4 @@ public static void main(String[] args) { } -} \ No newline at end of file +} From 326cbf1f4ea0aee7f4209c2456648c6553868c7d Mon Sep 17 00:00:00 2001 From: manasser99 <84741910+manasser99@users.noreply.github.com> Date: Sun, 20 Jun 2021 18:08:39 -0400 Subject: [PATCH 3/4] Add files via upload --- .../chapter10/solutions/BinaryReader.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/com/codefortomorrow/intermediate/chapter10/solutions/BinaryReader.java diff --git a/src/com/codefortomorrow/intermediate/chapter10/solutions/BinaryReader.java b/src/com/codefortomorrow/intermediate/chapter10/solutions/BinaryReader.java new file mode 100644 index 0000000..d5d24ff --- /dev/null +++ b/src/com/codefortomorrow/intermediate/chapter10/solutions/BinaryReader.java @@ -0,0 +1,58 @@ +/* + Create a program called BinaryReader in which a 4 x 4 + array of booleans is created. Have the computer loop + through the array, printing a 0 if the current element is + set to false and a 1 if it set to true. + + Example Array: + { + {true, false, false, true}, + {false, true, true, true}, + {true, true, false, true}, + {true, false, false, false} + } + + Example Output: + 1001 + 0111 + 1101 + 1000 +*/ + +public class BinaryReader +{ + public static void main(String[] args) + { + //Create a 2D array of booleans + boolean[][] arr = + { + {true, false, false, true}, + {false, true, true, true}, + {true, true, false, true}, + {true, false, false, false} + }; + + //Loop through the array using nested loops + for(int i = 0; i < arr.length; i++) + { + for(int j = 0; j < arr[0].length; j++) + { + //Check if current element is set to true + if(arr[i][j] == true) + { + //Print out a 1 if set to true + System.out.print(1); + } + //Otherwise, current element is set to false + else + { + //Print out a 0 if set to false + System.out.print(0); + } + } + + //Move over to the next line + System.out.println(); + } + } +} \ No newline at end of file From c3539e5db812884fbf7f60bbe632fc15928c61fd Mon Sep 17 00:00:00 2001 From: manasser99 <84741910+manasser99@users.noreply.github.com> Date: Sun, 20 Jun 2021 18:09:10 -0400 Subject: [PATCH 4/4] Update BinaryReader.java --- .../intermediate/chapter10/solutions/BinaryReader.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/com/codefortomorrow/intermediate/chapter10/solutions/BinaryReader.java b/src/com/codefortomorrow/intermediate/chapter10/solutions/BinaryReader.java index d5d24ff..a963d18 100644 --- a/src/com/codefortomorrow/intermediate/chapter10/solutions/BinaryReader.java +++ b/src/com/codefortomorrow/intermediate/chapter10/solutions/BinaryReader.java @@ -1,3 +1,5 @@ +package com.codefortomorrow.intermediate.chapter10.solutions; + /* Create a program called BinaryReader in which a 4 x 4 array of booleans is created. Have the computer loop @@ -55,4 +57,4 @@ public static void main(String[] args) System.out.println(); } } -} \ No newline at end of file +}