├── .DS_Store ├── ASCIIArt ├── BouncyBall.java ├── ROFLCOPTER.java └── Running.java ├── Arrays ├── ArrayListProj.java ├── TwoDimArrays.java └── ZombieKiller.java ├── Conditionals ├── .DS_Store ├── BooleanInJava.java ├── ComparisonOperators.java ├── IfElse.java └── SwitchCase.java ├── DataStructures ├── BBQ.java ├── HashBrowns.java ├── HashMapAwesomeness.java └── StacksRFun.java ├── ErrorsExceptions ├── Exceptions.java ├── NullPointerException.java └── TryCatchExamples.java ├── Loops ├── ForLoops.java ├── NestedLoops.java ├── NestedLoopsPattern.java └── WhileDo.java ├── Methods ├── JavaMethods.java ├── RecursionIsCool.java └── ReturnStatement.java ├── Numbers ├── DoubleLongFloat.java ├── Exponents.java ├── Integers.java └── StringInteger.java ├── Other ├── CurrentDate.java └── ScannerTut.java ├── Programs ├── .DS_Store ├── AddUserInput.java ├── AgeCalc.java ├── ArrowKeys.java ├── Factorial.java ├── Farts.java ├── JavaWebsiteCode.html ├── MagicBall.java ├── Palindromes.java ├── Primes.java ├── ReactFAST.java ├── ReadFile.java └── RollingDice.java ├── README.md └── Strings ├── .DS_Store ├── CommentsTutorial.java ├── DupChars.java ├── EscapingCharacters.java ├── HelloWorld.java ├── PartayScanner.java ├── PrintTutorial.java ├── ReverseString.java ├── StringMethods.java └── StringsProgram.java /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexlorenlee/JavaTutorialCode/4e0108ed0024242bddfb5179ddcb902cd85ecbe8/.DS_Store -------------------------------------------------------------------------------- /ASCIIArt/BouncyBall.java: -------------------------------------------------------------------------------- 1 | 2 | public class BouncyBall { 3 | 4 | public static void main(String[] args) throws InterruptedException { 5 | 6 | while (true) { 7 | System.out.println(" O "); 8 | System.out.println(" "); 9 | System.out.println("___"); 10 | 11 | Thread.sleep(100); 12 | 13 | System.out.println(); 14 | System.out.println(); 15 | System.out.println(); 16 | System.out.println(); 17 | System.out.println(); 18 | System.out.println(); 19 | System.out.println(); 20 | System.out.println(); 21 | System.out.println(); 22 | 23 | System.out.println(" | "); 24 | System.out.println(" O "); 25 | System.out.println("___"); 26 | 27 | Thread.sleep(100); 28 | 29 | System.out.println(); 30 | System.out.println(); 31 | System.out.println(); 32 | System.out.println(); 33 | System.out.println(); 34 | System.out.println(); 35 | System.out.println(); 36 | System.out.println(); 37 | System.out.println(); 38 | 39 | System.out.println(" "); 40 | System.out.println(" "); 41 | System.out.println("_O_"); 42 | 43 | Thread.sleep(100); 44 | 45 | System.out.println(); 46 | System.out.println(); 47 | System.out.println(); 48 | System.out.println(); 49 | System.out.println(); 50 | System.out.println(); 51 | System.out.println(); 52 | System.out.println(); 53 | System.out.println(); 54 | 55 | System.out.println(" "); 56 | System.out.println(" "); 57 | System.out.println("_<>_"); 58 | 59 | Thread.sleep(100); 60 | 61 | System.out.println(); 62 | System.out.println(); 63 | System.out.println(); 64 | System.out.println(); 65 | System.out.println(); 66 | System.out.println(); 67 | System.out.println(); 68 | System.out.println(); 69 | System.out.println(); 70 | 71 | System.out.println(" "); 72 | System.out.println(" "); 73 | System.out.println("_O_"); 74 | 75 | Thread.sleep(100); 76 | 77 | System.out.println(); 78 | System.out.println(); 79 | System.out.println(); 80 | System.out.println(); 81 | System.out.println(); 82 | System.out.println(); 83 | System.out.println(); 84 | System.out.println(); 85 | System.out.println(); 86 | 87 | System.out.println(" "); 88 | System.out.println(" O "); 89 | System.out.println("_|_"); 90 | 91 | Thread.sleep(100); 92 | 93 | System.out.println(); 94 | System.out.println(); 95 | System.out.println(); 96 | System.out.println(); 97 | System.out.println(); 98 | System.out.println(); 99 | System.out.println(); 100 | System.out.println(); 101 | System.out.println(); 102 | } 103 | 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /ASCIIArt/ROFLCOPTER.java: -------------------------------------------------------------------------------- 1 | 2 | public class ROFLCOPTER { 3 | 4 | public static void main(String[] args) throws InterruptedException { 5 | 6 | while (true) { 7 | 8 | System.out.println(); 9 | System.out.println(); 10 | System.out.println(); 11 | System.out.println(); 12 | System.out.println(); 13 | System.out.println(); 14 | System.out.println(); 15 | System.out.println(); 16 | 17 | System.out.println(" :LOL:ROFL:ROFL"); 18 | System.out.println(" A "); 19 | System.out.println(" /-------- "); 20 | System.out.println(" LOL==== ()\\ "); 21 | System.out.println(" L \\ \\ "); 22 | System.out.println(" \\_________] "); 23 | System.out.println(" I I "); 24 | System.out.println(" -----------/ "); 25 | System.out.println(" "); 26 | System.out.println(" Alex's ROFLCOPTER! "); 27 | 28 | Thread.sleep(100); 29 | 30 | System.out.println(); 31 | System.out.println(); 32 | System.out.println(); 33 | System.out.println(); 34 | System.out.println(); 35 | System.out.println(); 36 | System.out.println(); 37 | System.out.println(); 38 | 39 | System.out.println("ROFL:ROFL:LOL: "); 40 | System.out.println(" A "); 41 | System.out.println(" L /-------- "); 42 | System.out.println(" LOL==== ()\\ "); 43 | System.out.println(" \\ \\ "); 44 | System.out.println(" \\_________] "); 45 | System.out.println(" I I "); 46 | System.out.println(" -----------/ "); 47 | System.out.println(" "); 48 | System.out.println(" Alex's ROFLCOPTER! "); 49 | 50 | Thread.sleep(100); 51 | } 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /ASCIIArt/Running.java: -------------------------------------------------------------------------------- 1 | public class Running { 2 | 3 | public static void main(String[] args) throws InterruptedException { 4 | 5 | while (true) { 6 | System.out.println(" O "); 7 | System.out.println(" /|\\/ "); 8 | System.out.println(" \\/\\ "); 9 | System.out.println(" / "); 10 | 11 | Thread.sleep(100); 12 | 13 | System.out.println(); 14 | System.out.println(); 15 | System.out.println(); 16 | System.out.println(); 17 | System.out.println(); 18 | System.out.println(); 19 | System.out.println(); 20 | System.out.println(); 21 | System.out.println(); 22 | System.out.println(); 23 | 24 | System.out.println(" O "); 25 | System.out.println(" /|\\/ "); 26 | System.out.println(" /\\ "); 27 | System.out.println(" / | "); 28 | 29 | Thread.sleep(100); 30 | 31 | System.out.println(); 32 | System.out.println(); 33 | System.out.println(); 34 | System.out.println(); 35 | System.out.println(); 36 | System.out.println(); 37 | System.out.println(); 38 | System.out.println(); 39 | System.out.println(); 40 | System.out.println(); 41 | 42 | } 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Arrays/ArrayListProj.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class ArrayListProj { 4 | 5 | public static void main(String[] args) { 6 | 7 | String[] fruits = new String[4]; 8 | fruits[0] = "Mango"; 9 | fruits[1] = "Apple"; 10 | fruits[2] = "Strawberry"; 11 | fruits[3] = "Watermelon"; 12 | System.out.println(fruits); 13 | 14 | ArrayList fruitList = new ArrayList(); 15 | fruitList.add("Mango"); 16 | fruitList.add("Apple"); 17 | fruitList.add("Strawberry"); 18 | fruitList.add("Watermelon"); 19 | 20 | fruitList.remove("Strawberry"); 21 | // fruitList.clear(); 22 | System.out.println(fruitList.contains("Raspberry")); 23 | 24 | System.out.println(fruitList); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /Arrays/TwoDimArrays.java: -------------------------------------------------------------------------------- 1 | public class TwoDimArrays { 2 | 3 | public static void main(String[] args) { 4 | 5 | int[][] lotteryCard = { { 20, 15, 7 }, { 8, 7, 19 }, { 7, 13, 41 } }; 6 | 7 | int[][] lotteryCard2 = new int[3][3]; 8 | lotteryCard2[0][0] = 20; 9 | lotteryCard2[0][1] = 15; 10 | lotteryCard2[0][2] = 7; 11 | lotteryCard2[1][0] = 8; 12 | lotteryCard2[1][1] = 7; 13 | lotteryCard2[1][2] = 19; 14 | lotteryCard2[2][0] = 7; 15 | lotteryCard2[2][1] = 13; 16 | lotteryCard2[2][1] = 41; 17 | 18 | // [row][column] 19 | System.out.println(lotteryCard[0][0]); 20 | 21 | System.out.println("---------"); 22 | 23 | for (int i = 0; i <= 2; i++) { 24 | System.out.println(lotteryCard[i][i]); 25 | } 26 | 27 | System.out.println("---------"); 28 | 29 | for (int i = 0; i <= 2; i++) { 30 | for (int j = 0; j <= 2; j++) { 31 | System.out.println(lotteryCard[i][j]); 32 | } 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Arrays/ZombieKiller.java: -------------------------------------------------------------------------------- 1 | public class ZombieKiller { 2 | 3 | public static void main(String[] args) { 4 | System.out.println("Welcome to our zombie killer program!!!!"); 5 | 6 | String backpack[] = { "Shotgun", "Assault Rifle", "Sniper" }; 7 | String zombies[] = { "Close-range zombie", "Mid-range zombie", "Long-range zombie" }; 8 | 9 | System.out.println("Backpack items!"); 10 | System.out.println(backpack[0]); 11 | System.out.println(backpack[1]); 12 | System.out.println(backpack[2]); 13 | 14 | System.out.println("These are the zombies!"); 15 | System.out.println(zombies[0]); 16 | System.out.println(zombies[1]); 17 | System.out.println(zombies[2]); 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /Conditionals/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexlorenlee/JavaTutorialCode/4e0108ed0024242bddfb5179ddcb902cd85ecbe8/Conditionals/.DS_Store -------------------------------------------------------------------------------- /Conditionals/BooleanInJava.java: -------------------------------------------------------------------------------- 1 | public class BooleanInJava { 2 | 3 | public static void main(String[] args) { 4 | 5 | boolean passedDoor = true; 6 | boolean missedDoor = false; 7 | boolean passedAllDoors = false; 8 | int doorCount = 0; 9 | 10 | if(missedDoor) { 11 | System.out.println("We passed the first door!"); 12 | doorCount = doorCount + 1; 13 | } 14 | 15 | if(passedDoor) { 16 | System.out.println("We passed the second door!"); 17 | doorCount = doorCount + 1; 18 | } 19 | 20 | if(passedDoor) { 21 | System.out.println("We passed the third door!"); 22 | doorCount = doorCount + 1; 23 | } 24 | 25 | if(doorCount == 3) { 26 | passedAllDoors = true; 27 | } 28 | 29 | if(passedAllDoors) { 30 | System.out.println("Congratualions you won the program!"); 31 | } 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Conditionals/ComparisonOperators.java: -------------------------------------------------------------------------------- 1 | public class ComparisonOperators { 2 | 3 | public static void main(String[] args) { 4 | 5 | // == is equal to 6 | // != is not equal to 7 | // <= less than or equal to 8 | // < less than 9 | // > greater than 10 | // >= greater than or equal to 11 | // || OR 12 | // && AND 13 | 14 | double a = 2.4; 15 | 16 | if (a == 2.4) { 17 | System.out.println("They are equal!"); 18 | } 19 | 20 | if (a > 7) { 21 | System.out.println("Greater than 7"); 22 | } 23 | 24 | if (a == 2.4 || a == 2.5 || a == 6.1) { 25 | System.out.println("a is 2.4 or 2.5 or 6.1"); 26 | } 27 | 28 | if (a >= 0 && a <= 100 && a != 90) { 29 | System.out.println("a is in the range"); 30 | } 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Conditionals/IfElse.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class IfElse { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scan = new Scanner(System.in); 8 | System.out.println("Enter a grade:"); 9 | 10 | int n = scan.nextInt(); 11 | 12 | if (n >= 90 && n <= 100) { 13 | 14 | System.out.println("A"); 15 | 16 | } else if (n >= 80 && n < 90) { 17 | 18 | System.out.println("B"); 19 | 20 | } else if (n >= 70 && n < 80) { 21 | 22 | System.out.println("C"); 23 | 24 | } else if (n >= 65 && n < 70) { 25 | 26 | System.out.println("D"); 27 | 28 | } else if (n >= 0 && n < 65) { 29 | 30 | System.out.println("F"); 31 | 32 | } else { 33 | 34 | System.out.println("The number you entered is not in the range"); 35 | 36 | } 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /Conditionals/SwitchCase.java: -------------------------------------------------------------------------------- 1 | public class SwitchCase { 2 | 3 | public static void main(String[] args) { 4 | 5 | String dog = "great dane"; 6 | 7 | switch(dog) { 8 | case "pomeranian": 9 | System.out.println("small dog"); 10 | break; 11 | case "great dane": 12 | System.out.println("large dog"); 13 | break; 14 | default: 15 | System.out.println("try a different dog name"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /DataStructures/BBQ.java: -------------------------------------------------------------------------------- 1 | import java.util.LinkedList; 2 | import java.util.Queue; 3 | 4 | public class BBQ { 5 | 6 | public static void main(String[] args) { 7 | 8 | Queue q = new LinkedList(); 9 | 10 | q.add("A"); 11 | q.add("B"); 12 | q.add("C"); 13 | 14 | System.out.println(q.poll()); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /DataStructures/HashBrowns.java: -------------------------------------------------------------------------------- 1 | import java.util.HashSet; 2 | import java.util.Iterator; 3 | 4 | public class HashBrowns { 5 | 6 | public static void main(String[] args) { 7 | 8 | HashSet hashbrowns = new HashSet(); 9 | hashbrowns.add(13); 10 | hashbrowns.add(24); 11 | hashbrowns.add(5); 12 | 13 | Iterator it = hashbrowns.iterator(); 14 | while(it.hasNext()) { 15 | System.out.println(it.next()); 16 | } 17 | 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /DataStructures/HashMapAwesomeness.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | public class HashMapAwesomeness { 4 | 5 | public static void main(String[] args) { 6 | 7 | HashMap fun = new HashMap(); 8 | fun.put("bobbyJoe1996", "FluffyP0nies!"); 9 | fun.put("helloKittyFan21", "AloeVera?"); 10 | fun.put("coolguyswag", "password123"); 11 | 12 | System.out.println(fun.keySet()); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /DataStructures/StacksRFun.java: -------------------------------------------------------------------------------- 1 | import java.util.Stack; 2 | 3 | public class StacksRFun { 4 | 5 | public static void main(String[] args) { 6 | 7 | // Y 8 | // B 9 | // R 10 | 11 | Stack tower = new Stack(); 12 | 13 | tower.add('R'); 14 | tower.add('B'); 15 | tower.add('Y'); 16 | 17 | System.out.println(tower.size()); 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /ErrorsExceptions/Exceptions.java: -------------------------------------------------------------------------------- 1 | public class Exceptions { 2 | 3 | public static void main(String[] args) { 4 | 5 | String[] pets = { "dog", "cat", "monkey" }; 6 | System.out.println(pets[3]); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /ErrorsExceptions/NullPointerException.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class NullPointerException { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scan = null; 8 | scan.nextInt(); 9 | 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /ErrorsExceptions/TryCatchExamples.java: -------------------------------------------------------------------------------- 1 | public class TryCatchExamples { 2 | 3 | public static void main(String[] args) { 4 | 5 | try { 6 | 7 | int[] a = {4}; 8 | System.out.println(a[1]); 9 | 10 | } catch(NullPointerException e) { 11 | 12 | System.out.println("Your array is null!"); 13 | 14 | } catch(ArrayIndexOutOfBoundsException e) { 15 | 16 | System.out.println("Your index is out of bounds!"); 17 | 18 | } catch(Exception e) { 19 | 20 | System.out.println("Something else went wrong!"); 21 | 22 | } 23 | 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Loops/ForLoops.java: -------------------------------------------------------------------------------- 1 | public class ForLoops { 2 | 3 | public static void main(String[] args) { 4 | 5 | for (int i = 0; i < 4; i++) { 6 | System.out.println("I love cats!"); 7 | } 8 | 9 | for (int i = 0; i <= 15; i++) { 10 | System.out.println(i); 11 | } 12 | 13 | int[] grades = { 98, 100, 83, 90, 93 }; 14 | 15 | for (int i = 0; i < grades.length; i++) { 16 | System.out.println(grades[i]); 17 | } 18 | 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /Loops/NestedLoops.java: -------------------------------------------------------------------------------- 1 | public class NestedLoops { 2 | 3 | public static void main(String[] args) { 4 | 5 | for (int i = 0; i < 5; i++) { 6 | System.out.println("It's so freaking cold outside!"); 7 | } 8 | 9 | System.out.println("----------"); 10 | 11 | String[] colors = { "Red", "Blue", "Green" }; 12 | 13 | for (int i = 0; i < 3; i++) { 14 | System.out.println(colors[i]); 15 | } 16 | 17 | System.out.println("----------"); 18 | 19 | String[][] fancyColors = { { "Red", "Blue", "Green" }, { "Cyan", "Magenta", "Turqiouse" } }; 20 | 21 | for (int row = 0; row < 2; row++) { 22 | for (int column = 0; column < 3; column++) { 23 | System.out.println(fancyColors[row][column]); 24 | } 25 | } 26 | 27 | System.out.println("----------"); 28 | 29 | for (int i = 0; i < 5; i++) { 30 | for (int j = 0; j < 10; j++) { 31 | System.out.println("i: " + i + ", j: " + j); 32 | } 33 | } 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Loops/NestedLoopsPattern.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class NestedLoopsPattern { 4 | 5 | public static void main(String[] args) { 6 | 7 | System.out.println("Hello! How many stars would you like?"); 8 | Scanner scan = new Scanner(System.in); 9 | int numOfStars = scan.nextInt(); 10 | 11 | for (int i = 1; i <= numOfStars; i++) { 12 | for (int j = 0; j < i; j++) { 13 | System.out.print("*"); 14 | } 15 | System.out.println(); 16 | } 17 | 18 | for (int i = numOfStars - 1; i > 0; i--) { 19 | for (int j = 0; j < i; j++) { 20 | System.out.print("*"); 21 | } 22 | System.out.println(); 23 | } 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /Loops/WhileDo.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.Scanner; 3 | 4 | public class WhileDo { 5 | 6 | public static void main(String[] args) { 7 | 8 | String sentence = "flapjacks are awesome!"; 9 | Scanner scan = new Scanner(sentence); 10 | ArrayList words = new ArrayList(); 11 | 12 | while (scan.hasNext()) { 13 | words.add(scan.next()); 14 | } 15 | 16 | System.out.println(words); 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Methods/JavaMethods.java: -------------------------------------------------------------------------------- 1 | public class JavaMethods { 2 | 3 | public static void main(String[] args) { 4 | 5 | welcome(); 6 | multiply(5, 100); 7 | multiply(2, 3); 8 | multiply(6, 8); 9 | divide(20, 5); 10 | divide(100, 10); 11 | divide(66, 11); 12 | 13 | } 14 | 15 | public static void welcome() { 16 | System.out.println("Welcome to our calculator!"); 17 | } 18 | 19 | public static void multiply(int a, int b) { 20 | System.out.println(a * b); 21 | } 22 | 23 | public static void divide(int a, int b) { 24 | System.out.println(a / b); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /Methods/RecursionIsCool.java: -------------------------------------------------------------------------------- 1 | 2 | public class RecursionIsCool { 3 | 4 | public static void main(String[] args) { 5 | countBackwards(14); 6 | } 7 | 8 | public static void countBackwards(int n) { 9 | if(n == 0) { 10 | System.out.println("Done!"); 11 | } else { 12 | System.out.println(n); 13 | n--; 14 | countBackwards(n); 15 | } 16 | } 17 | 18 | //Need a base case 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Methods/ReturnStatement.java: -------------------------------------------------------------------------------- 1 | public class ReturnStatement { 2 | 3 | public static void main(String[] args) { 4 | String shouting = caps("why are you reading my diary mom?!"); 5 | System.out.println(shouting); 6 | 7 | int[] awesomeArray = gimmeArrayFromInts(3, 7, 1); 8 | System.out.println(awesomeArray[0]); 9 | System.out.println(awesomeArray[1]); 10 | System.out.println(awesomeArray[2]); 11 | } 12 | 13 | public static String caps(String s) { 14 | return s.toUpperCase(); 15 | } 16 | 17 | public static int[] gimmeArrayFromInts(int a, int b, int c) { 18 | int[] array = new int[3]; 19 | array[0] = a; 20 | array[1] = b; 21 | array[2] = c; 22 | return array; 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /Numbers/DoubleLongFloat.java: -------------------------------------------------------------------------------- 1 | public class DoubleLongFloat { 2 | 3 | public static void main(String[] args) { 4 | 5 | // https://cs.fit.edu/~ryan/java/language/java-data.html 6 | 7 | int a = -9; 8 | long b = 99999999999L; 9 | float c = 2.5F; 10 | double d = 5.4; 11 | 12 | System.out.println(a); 13 | System.out.println(b); 14 | System.out.println(c); 15 | System.out.println(d); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Numbers/Exponents.java: -------------------------------------------------------------------------------- 1 | public class Exponents { 2 | 3 | public static void main(String[] args) { 4 | 5 | int exponent = (int) Math.pow(2, 3); 6 | 7 | System.out.println(exponent); 8 | } 9 | 10 | } -------------------------------------------------------------------------------- /Numbers/Integers.java: -------------------------------------------------------------------------------- 1 | public class Integers { 2 | 3 | public static void main(String[] args) { 4 | 5 | int a = 5; 6 | int b = 2; 7 | int c = 0; 8 | int d = 9999999; 9 | int e = -700; 10 | 11 | System.out.println(a * b); 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /Numbers/StringInteger.java: -------------------------------------------------------------------------------- 1 | 2 | public class StringInteger { 3 | 4 | public static void main(String[] args) { 5 | 6 | String s = "age: 47"; 7 | s = s.replaceAll("\\D+",""); 8 | 9 | int n = Integer.parseInt(s); 10 | 11 | System.out.println(n + 2); 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Other/CurrentDate.java: -------------------------------------------------------------------------------- 1 | import java.text.SimpleDateFormat; 2 | import java.util.Date; 3 | 4 | public class CurrentDate { 5 | 6 | public static void main(String[] args) { 7 | 8 | // https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html 9 | 10 | Date currentDate = new Date(); 11 | System.out.println(currentDate); 12 | 13 | SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm:ss"); 14 | System.out.println(timeFormat.format(currentDate)); 15 | 16 | SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); 17 | System.out.println(dateFormat.format(currentDate)); 18 | 19 | SimpleDateFormat dayOfTheWeekFormat = new SimpleDateFormat("EEEE"); 20 | System.out.println(dayOfTheWeekFormat.format(currentDate)); 21 | 22 | SimpleDateFormat clockFormat = new SimpleDateFormat("h:mm a"); 23 | System.out.println(clockFormat.format(currentDate)); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /Other/ScannerTut.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ScannerTut { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scan = new Scanner(System.in); 8 | 9 | System.out.println("What's your first name?"); 10 | String name = scan.next(); 11 | 12 | System.out.println("What's your age?"); 13 | int age = scan.nextInt(); 14 | 15 | System.out.println("What's your senior quote?"); 16 | String quote = scan.next(); 17 | quote += scan.nextLine(); 18 | 19 | System.out.println("Thank you " + name + ", you are " + age + " years old"); 20 | System.out.println("and your senior quote is " + quote); 21 | 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Programs/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexlorenlee/JavaTutorialCode/4e0108ed0024242bddfb5179ddcb902cd85ecbe8/Programs/.DS_Store -------------------------------------------------------------------------------- /Programs/AddUserInput.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class AddUserInput { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scan = new Scanner(System.in); 8 | System.out.println("Enter a number:"); 9 | int a = scan.nextInt(); 10 | 11 | System.out.println("Enter another number:"); 12 | int b = scan.nextInt(); 13 | 14 | System.out.println(a + b); 15 | 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /Programs/AgeCalc.java: -------------------------------------------------------------------------------- 1 | import java.time.LocalDate; 2 | import java.time.Period; 3 | 4 | public class AgeCalc { 5 | 6 | public static void main(String[] args) { 7 | 8 | LocalDate today = LocalDate.now(); 9 | LocalDate birthDate = LocalDate.of(1996, 8, 18); 10 | int years = Period.between(birthDate, today).getYears(); 11 | 12 | System.out.println(today); 13 | System.out.println(birthDate); 14 | System.out.println(years); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /Programs/ArrowKeys.java: -------------------------------------------------------------------------------- 1 | import java.awt.event.KeyEvent; 2 | import java.awt.event.KeyListener; 3 | 4 | import javax.swing.*; 5 | 6 | public class ArrowKeys { 7 | 8 | public ArrowKeys() { 9 | JFrame frame = new JFrame(); 10 | frame.setVisible(true); 11 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 12 | frame.setSize(400, 400); 13 | frame.setFocusable(true); 14 | 15 | JPanel panel = new JPanel(); 16 | JLabel up = new JLabel(); 17 | JLabel down = new JLabel(); 18 | JLabel left = new JLabel(); 19 | JLabel right = new JLabel(); 20 | 21 | panel.add(up); 22 | panel.add(down); 23 | panel.add(right); 24 | panel.add(left); 25 | 26 | up.setText("Up: 0"); 27 | down.setText("Down: 0"); 28 | right.setText("Right: 0"); 29 | left.setText("Left: 0"); 30 | 31 | frame.addKeyListener(new KeyListener() { 32 | 33 | int upCount = 0; 34 | int downCount = 0; 35 | int rightCount = 0; 36 | int leftCount = 0; 37 | 38 | @Override 39 | public void keyTyped(KeyEvent e) { 40 | // TODO Auto-generated method stub 41 | 42 | } 43 | 44 | @Override 45 | public void keyPressed(KeyEvent e) { 46 | int keyCode = e.getKeyCode(); 47 | switch (keyCode) { 48 | case KeyEvent.VK_UP: 49 | up.setText("Up: " + Integer.toString(upCount++)); 50 | break; 51 | case KeyEvent.VK_DOWN: 52 | down.setText("Down: " + Integer.toString(downCount++)); 53 | break; 54 | case KeyEvent.VK_RIGHT: 55 | right.setText("Right: " + Integer.toString(rightCount++)); 56 | break; 57 | case KeyEvent.VK_LEFT: 58 | left.setText("Left: " + Integer.toString(leftCount++)); 59 | break; 60 | } 61 | } 62 | 63 | @Override 64 | public void keyReleased(KeyEvent e) { 65 | // TODO Auto-generated method stub 66 | 67 | } 68 | 69 | }); 70 | 71 | frame.add(panel); 72 | } 73 | 74 | public static void main(String[] args) { 75 | new ArrowKeys(); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /Programs/Factorial.java: -------------------------------------------------------------------------------- 1 | 2 | public class Factorial { 3 | 4 | public static void main(String[] args) { 5 | 6 | //5! = 5 * (4 * 3 * 2 * 1) = 120 7 | System.out.println(factorial(10)); 8 | } 9 | 10 | public static int factorial(int n) { 11 | if(n == 1) { 12 | System.out.println("factorial(" + n + ") = 1"); 13 | return 1; 14 | } else { 15 | System.out.println("factorial(" + n + ") = " + n + " * factorial(" + (n - 1) + ")"); 16 | return n * factorial(n - 1); 17 | } 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Programs/Farts.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | import java.util.Scanner; 3 | 4 | public class Farts { 5 | 6 | public static void main(String[] args) { 7 | 8 | System.out.println("Enter the first letter of your name and \n" 9 | + "the day of the month you were born: "); 10 | 11 | Scanner scan = new Scanner(System.in); 12 | 13 | String letter = scan.next().toUpperCase(); 14 | int day = scan.nextInt(); 15 | 16 | HashMap letters = new HashMap(); 17 | letters.put("A", "WRETCHED"); 18 | letters.put("B", "DEEPLY"); 19 | letters.put("C", "PHENOMENAL"); 20 | letters.put("D", "GROSSLY"); 21 | letters.put("E", "MONUMENTAL"); 22 | letters.put("F", "EXPLOSIVE"); 23 | letters.put("G", "UNEXPECTEDLY"); 24 | letters.put("H", "THICK"); 25 | letters.put("I", "TINY"); 26 | letters.put("J", "LONG"); 27 | letters.put("K", "GIGANTIC"); 28 | letters.put("L", "TREMENDOUS"); 29 | letters.put("M", "DANGEROUSLY"); 30 | letters.put("N", "CRAZY"); 31 | letters.put("O", "SCRAWNY"); 32 | letters.put("P", "BEAUTIFLY"); 33 | letters.put("Q", "ROTTENLY"); 34 | letters.put("R", "SPOOKY"); 35 | letters.put("S", "LUMPY"); 36 | letters.put("T", "MODERATELY"); 37 | letters.put("U", "HAPPY"); 38 | letters.put("V", "TROUBLESOME"); 39 | letters.put("W", "SAGGY"); 40 | letters.put("X", "HEARTY"); 41 | letters.put("Y", "BIG"); 42 | letters.put("Z", "LUXURIOUS"); 43 | 44 | HashMap days = new HashMap(); 45 | days.put(1, "SOUR"); 46 | days.put(2, "GREAT"); 47 | days.put(3, "OLD"); 48 | days.put(4, "LOUD"); 49 | days.put(5, "LITTLE"); 50 | days.put(6, "EPIC"); 51 | days.put(7, "WET"); 52 | days.put(8, "DANK"); 53 | days.put(9, "FAKE"); 54 | days.put(10, "SENILE"); 55 | days.put(11, "MUSTY"); 56 | days.put(12, "SHARP"); 57 | days.put(13, "DANGEROUS"); 58 | days.put(14, "MONOTONE"); 59 | days.put(15, "SQUEAKY"); 60 | days.put(16, "NOISELESS"); 61 | days.put(17, "ROTTEN"); 62 | days.put(18, "FAT"); 63 | days.put(19, "SOFT"); 64 | days.put(20, "POTENT"); 65 | days.put(21, "SUDDEN"); 66 | days.put(22, "POWERFUL"); 67 | days.put(23, "STRANGE"); 68 | days.put(24, "STURDY"); 69 | days.put(25, "FLAT"); 70 | days.put(26, "FULL"); 71 | days.put(27, "WINDY"); 72 | days.put(28, "HORRID"); 73 | days.put(29, "BEAUTIFUL"); 74 | days.put(30, "HOT"); 75 | days.put(31, "SILENT"); 76 | 77 | System.out.println("You are a " + letters.get(letter) + " " 78 | + days.get(day) + " FART"); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /Programs/JavaWebsiteCode.html: -------------------------------------------------------------------------------- 1 |

2 | Discover what fart you are! Simply enter the first letter of your name and the day of the month you were born! Ex: A 18 3 |

4 | 5 | 6 |

7 |
8 | 9 |
10 | 11 | 12 | 86 | -------------------------------------------------------------------------------- /Programs/MagicBall.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; 2 | import java.util.Scanner; 3 | 4 | public class MagicBall { 5 | 6 | public static void main(String[] args) { 7 | System.out.println("Enter your question"); 8 | 9 | Scanner scan = new Scanner(System.in); 10 | scan.next(); 11 | scan.close(); 12 | 13 | Random rand = new Random(); 14 | int r = rand.nextInt(5); 15 | System.out.println(r); 16 | 17 | if(r == 0) { 18 | System.out.println("As I see it, yes."); 19 | } else if(r == 1) { 20 | System.out.println("Signs point to yes."); 21 | } else if(r == 2) { 22 | System.out.println("Reply hazy, try again."); 23 | } else if(r == 3) { 24 | System.out.println("Don't count on it."); 25 | } else if(r == 4) { 26 | System.out.println("Outlook not so good."); 27 | } 28 | 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Programs/Palindromes.java: -------------------------------------------------------------------------------- 1 | 2 | public class Palindromes { 3 | 4 | public static void main(String[] args) { 5 | 6 | //Ex: mom, dad, poop, race car, nurses run 7 | 8 | String original = "nurses rund"; 9 | original = original.replace(" ", ""); 10 | 11 | String reverse = ""; 12 | for(int i = original.length() - 1; i >= 0; i--) { 13 | reverse += original.charAt(i); 14 | System.out.println(reverse); 15 | } 16 | 17 | boolean palindrome = true; 18 | for(int i = 0; i < original.length(); i++) { 19 | if(original.charAt(i) != reverse.charAt(i)) { 20 | palindrome = false; 21 | } 22 | } 23 | 24 | if(palindrome) { 25 | System.out.println("PALINDROME!"); 26 | } else { 27 | System.out.println("Not a palindrome!"); 28 | } 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Programs/Primes.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class Primes { 4 | 5 | public static void main(String[] args) { 6 | 7 | System.out.println(findPrimes(1, 100)); 8 | 9 | } 10 | 11 | public static ArrayList findPrimes(int start, int end) { 12 | 13 | ArrayList primes = new ArrayList(); 14 | 15 | for(int n = start; n < end; n++) { 16 | boolean prime = true; 17 | 18 | int i = 2; 19 | while(i <= n/2) { 20 | if(n % i == 0) { 21 | prime = false; 22 | break; 23 | } 24 | i++; 25 | } 26 | 27 | if(prime) { 28 | primes.add(n); 29 | } 30 | } 31 | 32 | return primes; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Programs/ReactFAST.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class ReactFAST { 4 | 5 | public static void main(String[] args) throws InterruptedException { 6 | 7 | System.out.println("3"); 8 | Thread.sleep(1000); 9 | System.out.println("2"); 10 | Thread.sleep(1000); 11 | System.out.println("1"); 12 | Thread.sleep(1000); 13 | 14 | System.out.println("GO!!!!!!!!!"); 15 | long startTime = System.currentTimeMillis(); 16 | 17 | Scanner s = new Scanner(System.in); 18 | s.next(); 19 | long stopTime = System.currentTimeMillis(); 20 | 21 | long reactionTime = stopTime - startTime; 22 | 23 | System.out.println(reactionTime + "ms"); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Programs/ReadFile.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.FileNotFoundException; 3 | import java.io.FileWriter; 4 | import java.io.IOException; 5 | import java.util.Scanner; 6 | 7 | public class ReadFile { 8 | 9 | public static void main(String[] args) throws IOException { 10 | 11 | // http://textfiles.com/100/captmidn.txt 12 | 13 | File file = new File("/Users/alexlee/Desktop/captmidn.txt"); 14 | Scanner scan = new Scanner(file); 15 | 16 | String fileContent = "THIS IS A NEW FILE MADE BY US"; 17 | while (scan.hasNextLine()) { 18 | fileContent = fileContent.concat(scan.nextLine() + "\n"); 19 | } 20 | 21 | FileWriter writer = new FileWriter("/Users/alexlee/Desktop/newfile.txt"); 22 | writer.write(fileContent); 23 | writer.close(); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Programs/RollingDice.java: -------------------------------------------------------------------------------- 1 | import java.util.Random; 2 | 3 | public class RollingDice { 4 | 5 | public static void main(String[] args) { 6 | 7 | Random rand = new Random(); 8 | int result = rand.nextInt(6) + 1; 9 | System.out.println("You rolled a: " + result); 10 | 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JavaTutorialCode 2 | 3 | Here's the code from videos on my channel: https://www.youtube.com/channel/UC_fFL5jgoCOrwAVoM_fBYwA 4 | -------------------------------------------------------------------------------- /Strings/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexlorenlee/JavaTutorialCode/4e0108ed0024242bddfb5179ddcb902cd85ecbe8/Strings/.DS_Store -------------------------------------------------------------------------------- /Strings/CommentsTutorial.java: -------------------------------------------------------------------------------- 1 | public class CommentsTutorial { 2 | 3 | public static void main(String[] args) { 4 | // The code below prints text to the screen 5 | // Muahaha this line does nothing! 6 | 7 | /* 8 | * These are all comments too! 9 | */ 10 | 11 | // System.out.print("1"); 12 | System.out.print("2"); 13 | // System.out.print("3"); 14 | 15 | System.out.print("A"); 16 | // System.out.print("B"); 17 | System.out.print("C"); 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /Strings/DupChars.java: -------------------------------------------------------------------------------- 1 | public class DupChars { 2 | 3 | public static void main(String[] args) { 4 | 5 | String sentence = "How many duplicates are there?"; 6 | System.out.println(sentence); 7 | 8 | String characters = ""; 9 | String duplicates = ""; 10 | for (int i = 0; i < sentence.length(); i++) { 11 | String current = Character.toString(sentence.charAt(i)); 12 | if (characters.contains(current)) { 13 | if (!duplicates.contains(current)) { 14 | duplicates += current + ","; 15 | } 16 | } 17 | characters += current; 18 | } 19 | 20 | System.out.println(duplicates); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Strings/EscapingCharacters.java: -------------------------------------------------------------------------------- 1 | public class EscapingCharacters { 2 | 3 | public static void main(String[] args) { 4 | 5 | System.out.println("What do you mean \"stinky\""); 6 | System.out.println("The file is located at ~\\Desktop\\FunnyCatPics"); 7 | System.out.println("This is a tab \t!"); 8 | System.out.println("This \n is \n on \n multiple lines"); 9 | 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Strings/HelloWorld.java: -------------------------------------------------------------------------------- 1 | public class HelloWorld { 2 | 3 | public static void main(String[] args) { 4 | System.out.println("Hello World"); 5 | } 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Strings/PartayScanner.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class PartayScanner { 4 | 5 | public static void main(String[] args) { 6 | 7 | Scanner scan = new Scanner(System.in); 8 | 9 | System.out.println("Enter pokemon 1:"); 10 | String pokemon1 = scan.nextLine(); 11 | 12 | System.out.println("Enter pokemon 2:"); 13 | String pokemon2 = scan.nextLine(); 14 | 15 | System.out.println("Enter pokemon 3:"); 16 | String pokemon3 = scan.nextLine(); 17 | 18 | System.out.println("Enter pokemon 4:"); 19 | String pokemon4 = scan.nextLine(); 20 | 21 | System.out.println("Enter pokemon 5:"); 22 | String pokemon5 = scan.nextLine(); 23 | 24 | System.out.println("Enter pokemon 6:"); 25 | String pokemon6 = scan.nextLine(); 26 | 27 | System.out.println("Here are your pokemon!"); 28 | System.out.println(pokemon1); 29 | System.out.println(pokemon2); 30 | System.out.println(pokemon3); 31 | System.out.println(pokemon4); 32 | System.out.println(pokemon5); 33 | System.out.println(pokemon6); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /Strings/PrintTutorial.java: -------------------------------------------------------------------------------- 1 | public class PrintTutorial { 2 | 3 | public static void main(String[] args) { 4 | System.out.println("A"); 5 | System.out.println("B"); 6 | System.out.println("C"); 7 | System.out.println("D"); 8 | System.out.println("E"); 9 | 10 | System.out.print("A"); 11 | System.out.print("B"); 12 | System.out.print("C"); 13 | System.out.print("D"); 14 | System.out.print("E"); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Strings/ReverseString.java: -------------------------------------------------------------------------------- 1 | public class ReverseString { 2 | 3 | public static void main(String[] args) { 4 | 5 | String r = reverse("Pomegranites are amazing!!!!"); 6 | System.out.println(r); 7 | } 8 | 9 | public static String reverse(String s) { 10 | char[] letters = new char[s.length()]; 11 | 12 | int letterIndex = 0; 13 | for(int i = s.length() - 1; i >= 0; i--) { 14 | letters[letterIndex] = s.charAt(i); 15 | letterIndex++; 16 | } 17 | 18 | String reverse = ""; 19 | for(int i = 0; i < s.length(); i++) { 20 | reverse = reverse + letters[i]; 21 | } 22 | 23 | return reverse; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Strings/StringMethods.java: -------------------------------------------------------------------------------- 1 | public class StringMethods { 2 | 3 | public static void main(String[] args) { 4 | 5 | String name = "Billy Bob Joe"; 6 | 7 | System.out.println("Normal: " + name); 8 | System.out.println("To uppercase: " + name.toUpperCase()); 9 | System.out.println("To lowercase: " + name.toLowerCase()); 10 | System.out.println("First character: " + name.charAt(0)); 11 | System.out.println("Length: " + name.length()); 12 | System.out.println("Last character: " + name.charAt(12)); 13 | System.out.println("Last name: " + name.substring(10, 13)); 14 | 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /Strings/StringsProgram.java: -------------------------------------------------------------------------------- 1 | public class StringsProgram { 2 | 3 | public static void main(String[] args) { 4 | System.out.println("Madlibs!"); 5 | 6 | String username = "magicPony420!"; 7 | 8 | System.out.println("My ____ sister accidentally ___ed all over her new ___"); 9 | 10 | String adjective = "flamboyant"; 11 | String verb = "fart"; 12 | String noun = "pogo stick"; 13 | 14 | System.out.println("My " + adjective + " sister accidentally " + verb + "ed all over her new " + noun); 15 | } 16 | 17 | } --------------------------------------------------------------------------------