Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy Quartz site to GitHub Pages

on:
push:
branches:
- v4

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for git info
- uses: actions/setup-node@v3
with:
node-version: 18.14
- name: Install Dependencies
run: npm ci
- name: Build Quartz
run: npx quartz build
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: public

deploy:
needs: build
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
Empty file removed content/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions content/2D Arrays.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Famous question: Creating minesweeper
61 changes: 61 additions & 0 deletions content/Array Lists.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# YESSSS
- An empty list
- To access it, you use special methods
- The data type between the carets <> must be classes (which are usually uppercase)

| `Class` | `Not a class` |
| --------- | ------------- |
| Integer | int |
| Character | char |
| Boolean | boolean |
| String | - |
| Scanner | - |

# Instancing
```java
// Making an arraylist variable;
ArrayList<Integer> arrayList = new Arraylist<Integer>();

// You can also ignore the type when instancing the array list
ArrayList<Integer> arrayList = new Arraylist<>();
```

# Methods
We only know:
- add()
- get()
- indexOf()
- remove()
- size()
#### Add
```java
arrayList.add(10); // Adds 10 to the array; now size 1
arrayList.add(20); // Adds 20 to the array; now size 2
arrayList.add(0, 1); // Adds 1 at index 0;
arrayList.add(4, 1); // Runtime error, because the array is only of size 3; it's biggest index is 2 and adding another element could at most be index 3.
```
#### Get
```java
int index1 = arrayList.get(1); // Gets the item at index 1 (arrayLists are also indexed from 0 onwards);
```
#### Index of
```java
System.out.println(arrayList); // printing arraylists works!
int indexOf10 = arrayList.indexOf(10); // Will find the occurance of 10 in array lists
```
#### Remove
```java
// Removes the item in index 2. Everything on the right of index 2 is shifted
arrayList.remove(2);
```
#### Size
```java
// Gets the size of the array. Like length or length() in arrays and strings.
arrayList.size();
```

#### Set
```java
// Sets index 0 to the value of 1000.
arrayList.set(0, 1000);
```
79 changes: 79 additions & 0 deletions content/Arrays.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
## Data structures
A [[Variables|variable]] holds 1 bit of data at a time.
To hold many values, we can use some data structures:
- 1 dimensional array
- [[2D Arrays|2 dimensional array]]
- [[Array Lists|ArrayList<>]]
- Map<> (Dictionaries)

Other structures include:
- Stacks
- Queues
- Linked Lists
- Binary Trees
- etc

# Using arrays
### Declaring
```java
// This declares a 1 dimensional array
int [] intArr1 = new int[5];
// java will default the values in the array to 0 b/c it's a primary type "int"

// To set a value, you just index the position
intArr1[0] = 10; // index 0 will have an int value of 10.

// Another way of declaring an array is via curly brackets
// You do not need to "new" anything; just the brackets work.
int [] intArr2 = {1, 2, 3, 4, 5};
```
### ArrayIndexOutOfBoundsException
```java
int [] intArr1 = new int[5];
intArr1 = 10;
System.out.println(intArr[0]); // Will print 10
intArr1[5] = 10; // Will throw a *runtime error* because 5 is outside the range of [0, 4]. Code before will run, but once it reaches this line it will break.
```

### Array Methods
```java
int [] intArr1 = new int[5];
int length = intArr1.length; // Will be 5
// We use intArr1.length INSTEAD OF "string".length(); because an array has a constant length.

```


# Passing arrays into methods
I made an example. Just look at it; it is very straight forward.
```java
/*
@param intArr is an integer array
@return the sum of all the elements
*/
public static int arraySum(int[] intArr) {
int intSum = 0;

// This is an example of using "for each"
for (int k : intArr)
intSum += k;
return intSum;
}
```

# Misc info
Some common algorithms we need to know:
- Finding Max / Min
- Sorting

Use [[2D Arrays]] for grids and stuff

Arrays are a constant size.
Use an ArrayList<> for dynamically sizing array.
Use a Map to hold a pair of data. Like a dictionary.

## What happens if you literally print an array!?
```java
int[] array = new int[1];
System.out.println(array); // this will print a memory location in hexadecimal (base 16)
```
25 changes: 25 additions & 0 deletions content/Conditionals or Selections.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
if statements n stuff

### Short-circuit evaluation
```java
int x = 10;
int y = 0;
// It will skip the second condition b/c the first condition is true
if (x < 20 || x / y == 0) {
// It will print this; no runtime error
}
if (x < 20 && x / y == 0) {
// This will throw a run-time error because && will run both conditionals.
// The conditional for x / y will give an arithmetic error
}

```

### Syntactic sugar
```java
// Will call the line directly after if there's no curly brackets '{}'
if (true) System.out.println("This will print if true!");

System.out.println("This will print regardless!");

```
14 changes: 14 additions & 0 deletions content/De Morgan's Law.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

| Express-<br>ion | **A** | **B** | A \|\| B | A && B | !A | !B | !A \|\| !B | !A && !B |
| --------------- | ----- | ----- | ------------ | -------------- | --- | --- | ---------- | ------------ |
| | T | T | T | T | F | F | F | F |
| | T | F | T | F | F | T | T | F |
| | F | T | T | F | T | F | T | F |
| | F | F | F | F | T | T | T | T |
| Same<br>as | | | ! (!A && !B) | ! (!A \|\| !B) | | | !(A && B) | ! (A \|\| B) |


![[Pasted image 20240220132055.png]]![[Pasted image 20240220132805.png]]
![[Pasted image 20240220133100.png]]


24 changes: 24 additions & 0 deletions content/Flow charts for conditionals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
flow charts yay
* Oval = beginning
* parallelogram
* Assigning variables
* Getting user input
* Output
* Diamond = conditions
* Square
* Describes a condition (true / false arrow)


Note:
* Do not write exact code



The top image is an oval that says "start"
![[Pasted image 20240221144302.png]]

(newer)
![[Pasted image 20240222132119.png]]

- The point of the parallelogram is to specify input and output.
-
55 changes: 55 additions & 0 deletions content/For loops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

```java
// This will loop so long as i, which is declared *inside* the for loop, is less than 10. If it isn't, the loop will not continue.
for (int i = 0; i < 10; i++) {
// I will be the values between [0, 9]
}
```

```java
int i;
// This for loop doesn't have a body, so it just makes i equal to 9 at the end of the loop.
for (i = 0; i < 10; i++);
s.o.p(i); // Will print 9
```

```java
// Similarly to conditionals, if you don't add the curly braces or semicolon, it will only loop the line right after it.
for (int i = 0; i < 10; i++)
s.o.p(i); // Prints 0 to 9
s.o.p("This is only printed once!");
```

## For each
To iterate over every item in an [[Arrays|array]] without needing the index, you can use a for each loop
```java
int[] intArr = {1,2,3,4,5};
// The variable represents 1 item in the array.
for (int k : intArr) {
// do whatever you want with k, and the loop will continue until all "k"'s are used up.
}

```

## Semantics with ++
The "++" operator can be written two ways:
```java
int variable = 0;
variable++; // First way
++variable; // Second way
```
...and there is a big difference between the two of them!1
1. `var++` will get the value of `var`, and *then* increment by one
2. `++var` will increment the value, and then will give that incremented value of `var`
>[!help] Yes. it doesn't make much sense at first. Bear with me

```java
int first = 0;
System.out.println(first++); // "0" is printed, then "first" increments by 1.

int second = 0;
System.out.println(++second); // "second" will be incremented, and then "1" is printed.
```
>In both cases, `first` and `second` increment by 1, but the time at which the variables "update" is different


Loading