Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
bowbahdoe committed Sep 17, 2024
1 parent 316d6fc commit 08f0237
Showing 1 changed file with 40 additions and 4 deletions.
44 changes: 40 additions & 4 deletions src/arrays/set_individual_elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,26 @@ the new value.[^strings]
```java
~void main() {
String[] sentence = { "you", "are", "found", "guilty" };
System.out.println(sentence);
System.out.println(
sentence[0]
+ " "
+ sentence[1]
+ " "
+ sentence[2]
+ " "
+ sentence[3]
);

sentence[1] = "aren't";
System.out.println(sentence);
System.out.println(
sentence[0]
+ " "
+ sentence[1]
+ " "
+ sentence[2]
+ " "
+ sentence[3]
);
~}
```

Expand All @@ -22,10 +38,30 @@ The index of the element to set can also come from a variable.
~void main() {
int index = 2;
String[] response = { "and", "it", "isn't", "opposite", "day" };
System.out.println(response);
System.out.println(
sentence[0]
+ " "
+ sentence[1]
+ " "
+ sentence[2]
+ " "
+ sentence[3]
+ " "
+ sentence[4]
);

response[2] = "is";
System.out.println(response);
System.out.println(
sentence[0]
+ " "
+ sentence[1]
+ " "
+ sentence[2]
+ " "
+ sentence[3]
+ " "
+ sentence[4]
);
~}
```

Expand Down

0 comments on commit 08f0237

Please sign in to comment.