mirror of
https://github.com/Brandon-Rozek/website.git
synced 2025-10-10 15:01:15 +00:00
Website snapshot
This commit is contained in:
parent
ee0ab66d73
commit
50ec3688a5
281 changed files with 21066 additions and 0 deletions
45
content/ta/spring2018/cpsc220/midtermreview.md
Normal file
45
content/ta/spring2018/cpsc220/midtermreview.md
Normal file
|
@ -0,0 +1,45 @@
|
|||
# More Midterm Review
|
||||
|
||||
Let us suppose that we have the following array
|
||||
|
||||
```java
|
||||
int[] b = {11, 12, 15, 16, 21}
|
||||
```
|
||||
|
||||
## Increase all elements by 2
|
||||
|
||||
```java
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
b[i] += 2;
|
||||
}
|
||||
```
|
||||
|
||||
## Print all elements of array
|
||||
|
||||
```java
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
System.out.println(b[i]);
|
||||
}
|
||||
```
|
||||
|
||||
## Sum all the elements of an array
|
||||
|
||||
```java
|
||||
int sum = 0;
|
||||
for (int i = 0; i < b.length; i++) {
|
||||
sum += b[i];
|
||||
}
|
||||
```
|
||||
|
||||
## Access Last Element of Array
|
||||
|
||||
```java
|
||||
System.out.println(b[b.length - 1]);
|
||||
```
|
||||
|
||||
## Access the middle element
|
||||
|
||||
```java
|
||||
System.out.println(b[b.length / 2]);
|
||||
```
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue