This file contains hidden or 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
| # Variables | |
| x = 5 | |
| y = 1.5 | |
| name = "John" | |
| is_active = True | |
| # Conditionals | |
| if x > y: | |
| print("x is greater than y") | |
| elif x < y: |
This file contains hidden or 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 Tower_of_Hanoi { | |
| static void towerOfHanoi(int n, char first_rod, char third_rod, char second_rod){ | |
| if (n == 1) { | |
| System.out.println("Move disk 1 from rod " + first_rod + " to rod " + third_rod); | |
| return; | |
| } | |
| towerOfHanoi(n - 1, first_rod, second_rod, third_rod); | |
| System.out.println("Move disk " + n + " from rod " + first_rod + " to rod " + third_rod); | |
| towerOfHanoi(n - 1, second_rod, third_rod, first_rod); |
This file contains hidden or 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 enum ObjectOrientedProgrammingLanguages { | |
| JAVA, | |
| PYTHON, | |
| CPP | |
| } |
This file contains hidden or 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 App { | |
| public static void main(String[] args) { | |
| System.out.println(ObjectOrientedProgrammingLanguages.JAVA); | |
| for(ObjectOrientedProgrammingLanguages oopLanguages : ObjectOrientedProgrammingLanguages.values()){ | |
| System.out.println(oopLanguages); | |
| } | |
| } | |
| } |
This file contains hidden or 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
| class OuterClass { | |
| void printMessage(){ | |
| System.out.println("This is the outer class!"); | |
| } | |
| class InnerClass { | |
| void print(){ | |
| System.out.println("This is the inner class!"); | |
| } | |
| } | |
| } |
This file contains hidden or 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.Scanner; | |
| interface Event { | |
| String message = "An event has been triggered!"; | |
| void printMessage(); | |
| } | |
| public class App { | |
| public static void main(String[] args) { |
This file contains hidden or 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.io.File; | |
| import java.io.FileNotFoundException; | |
| import java.io.FileWriter; | |
| import java.io.IOException; | |
| import java.util.Scanner; | |
| public class App { | |
| public static void main(String[] args) throws IOException { | |
| File file = new File("text"); | |
| Scanner scanner = new Scanner(file); |
This file contains hidden or 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.io.File; | |
| import java.io.FileNotFoundException; | |
| import java.io.FileReader; | |
| public class App { | |
| public static void main(String[] args) { | |
| //Example of checked exception | |
| File file = new File("C:\\randomname.txt"); | |
| try { |
This file contains hidden or 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.Objects; | |
| public class Laptop extends Computer { | |
| private String manufacturer; | |
| public String getManufacturer() { | |
| return manufacturer; | |
| } |
This file contains hidden or 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 App { | |
| public static void main(String[] args) { | |
| Laptop laptop = new Laptop(); | |
| laptop.setManufacturer("HP"); | |
| System.out.println(laptop); | |
| } | |
| } |