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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions FizzBuzz.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The markdown format is commonly used for things like readme files, as they allow
which allows for basic typesetting when viewed while still being a plaintext format.

Below is a blank checkbox:
- [ ] Put an X in the [ ] to mark this as done!
- [X] Put an X in the [ ] to mark this as done!

You can edit this file directly to check off these checkboxes throughout the lab to mark things as done.
Do so now for the checkbox above.
Expand Down Expand Up @@ -117,7 +117,7 @@ class FizzBuzz {
}
```

- [ ] Open `FizzBuzz.java` in the `src` directory and click the run button in the top left corner.
- [X] Open `FizzBuzz.java` in the `src` directory and click the run button in the top left corner.

If you don't see this button, you may need to mark `src` as the `Sources Root` for the project. You can do this
by right-clicking the `src` directory in the `Project` tab and near the bottom of the context menu
Expand All @@ -135,7 +135,7 @@ the code are doing. For example, what's the Java version of Python's `and`? What
on with that weird `for` loop? As you do this, you might find it useful to write down your
own implementation in Python to help you begin to create a mapping between the two languages.

- [ ] Make note of any specific Java syntax which stands out to you and compare what you
- [X] Make note of any specific Java syntax which stands out to you and compare what you
come up with those around you. Try to come up with a list of at least five things that
strike you as either similar to or different from Python.

Expand All @@ -160,7 +160,7 @@ Later in this course, you'll learn what all that mess means, but for now it is e

### Task 1.1: Rewrite this using `while`

- [ ] You've puzzled through how Java `for` and `if` statements work; now rewrite this
- [X] You've puzzled through how Java `for` and `if` statements work; now rewrite this
to use a `while` loop instead of a `for` loop.

## How to test this code
Expand All @@ -179,7 +179,7 @@ line or the closing brace `}` of the loop.

3. Immediately, type the method name you want, maybe something like `doFizzBuzz`.

- [ ] Rerun the program to verify.
- [X] Rerun the program to verify.

That's your first big IntelliJ trick! There are lots more.

Expand All @@ -192,7 +192,7 @@ You'll learn more about the various access modifiers in your Java readings soon.

Now that you've made your first edits to your code, you should ask git to save these changes for you.

- [ ] Open the Terminal tab in IntelliJ and type `git status`, it will show you that you have modified `FizzBuzz.java` (and this README too!).
- [X] Open the Terminal tab in IntelliJ and type `git status`, it will show you that you have modified `FizzBuzz.java` (and this README too!).

We will save our local changes to `FizzBuzz.java` and then push the changes to your GitHub repository using
a sequence of three git commands:
Expand Down Expand Up @@ -241,12 +241,12 @@ Now, back to exploring the code!

To briefly observe what private does, let's create a new class.

- [ ] Right-click on `src` and select `New —> Java Class`. Name it `Main`. This will create a `Main.java` file.
- [X] Right-click on `src` and select `New —> Java Class`. Name it `Main`. This will create a `Main.java` file.

We'll write a main method which will attempt to call `FizzBuzz.doFizzBuzz` (or whatever you called
your extracted helper method).

- [ ] To quickly generate `main`, you can start typing `psvm` in IntelliJ and then press Enter to accept the
- [X] To quickly generate `main`, you can start typing `psvm` in IntelliJ and then press Enter to accept the
autocomplete — it will generate an empty "public static void main" (psvm) method for you. Neat!

- [ ] In the body of this main method, type `FizzBuzz.`. You'll see that the private helper method doesn't
Expand Down
35 changes: 21 additions & 14 deletions src/FizzBuzz.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,38 @@
class FizzBuzz {

public static void main(String[] args) {
int i = 0;

for (int i = 1; i < 100; i++) {
while (i < 100) {

// Find out which numbers divide i.
boolean divisibleBy3 = i % 3 == 0;
boolean divisibleBy5 = i % 5 == 0;
i = checkingLoop(i);
}
}

public static int checkingLoop(int i) {
// Find out which numbers divide i.
boolean divisibleBy3 = i % 3 == 0;
boolean divisibleBy5 = i % 5 == 0;

// Print our appropriate result.
if (divisibleBy3 && divisibleBy5) {
// Print our appropriate result.
if (divisibleBy3 && divisibleBy5) {

System.out.println("Fizz Buzz");
System.out.println("Fizz Buzz");

} else if (divisibleBy3) {
} else if (divisibleBy3) {

System.out.println("Fizz");
System.out.println("Fizz");

} else if (divisibleBy5) {
} else if (divisibleBy5) {

System.out.println("Buzz");
System.out.println("Buzz");

} else {
} else {

System.out.println(i);
System.out.println(i);

}
}
i++;
return i;
}
}
6 changes: 6 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class Main {
public static void main(String[] args) {
FizzBuzz.checkingLoop(5
System.out.println("The change");
}
}
12 changes: 12 additions & 0 deletions src/Multiples.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
public class Multiples {
public static void main(String[] args) {
int count = 0;

for (int i = 0; i < 1000; i++) {
if (i % 3 == 0 || i % 5 == 0) {
count++;
}
}
System.out.println(count);
}
}
17 changes: 17 additions & 0 deletions src/Reduce.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Reduce {
public static void main(String[] args) {
int steps = 0;
int n = 100;

while (n > 0) {
if (n % 2 == 0) {
n = n / 2;
} else {
n = n - 1;
}
steps++;
}

System.out.println(steps);
}
}