This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FizzBuzz { | |
public static void main(String[] args) { | |
for(int i = 0 ; i < 100 ; ++i) { | |
boolean fizz = i % 3 == 0; | |
boolean buzz = i % 5 == 0; | |
if (fizz && buzz) { | |
System.out.println("FizzBuzz"); | |
} else if (fizz) { | |
System.out.println("Fizz"); | |
} else if (buzz) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
public class Methods { | |
public static void main(String[] args) { | |
// Methods are just functions that belong to a particular class | |
// Methods are sub-routines. Reusable code. | |
// Method have parameters, are called with arguments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Question 1 | |
public static boolean isVowell(char letter) { | |
switch (letter) { | |
case 'a': | |
case 'e': | |
case 'i': | |
case 'o': | |
case 'u': | |
return true; | |
case 'y': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Constructors { | |
// Constructors initializes a class for use | |
// They must have the same name as the name of the class | |
public static class Cube { | |
// You can provide initial values for your instance variables like so | |
// (You don't necessarily need to do this in a constructor) | |
private int length = 1; | |
private int width = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DigitalWallet { | |
private static double maxWithdrawalPct = .5; | |
private long accountId; | |
private long balance = 0; | |
private TransactionHistory transactions = new TransactionHistory(); | |
public DigitalWallet(long accountId) { | |
this.accountId = accountId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TestDigitalWallet { | |
public static void main(String[] args) { | |
DigitalWallet w1 = new DigitalWallet(1); | |
w1.deposit(10000); | |
w1.withdraw(5000); | |
DigitalWallet.setMaxWithdrawalPct(.75); | |
System.out.println(w1.canWithdraw(4000)); // false | |
DigitalWallet w2 = new DigitalWallet(2, 20000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Recursion { | |
public static class ExampleOne | |
{ | |
public static void main (String args[]) | |
{ | |
count(0); | |
} | |
public static void count (int index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BigO { | |
// Big O notation is used in Computer Science to describe the performance or complexity of an algorithm. | |
// Big O specifically describes the worst-case scenario, and can be used to describe | |
// the execution time required or the space used | |
// O(1) describes an algorithm that will always execute in the same time (or space) | |
// regardless of the size of the input data set. | |
private String[] strings = { "", null }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StackExercises { | |
public static void main(String[] args) { | |
// Reverse | |
System.out.println("Reverse:"); | |
System.out.println( | |
"12345 => " + reverse("12345") + '\n' + | |
"randy => " + reverse("randy") + '\n' + | |
"2 => " + reverse("2") | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
// Let me know if you find any mistakes!! | |
public class FinalReview { | |
public static void main(String[] args) { | |
System.out.println("Question 1:"); | |
List<String> list = new ArrayList<>(); | |
list.add("1"); |
OlderNewer