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.Scanner; | |
class Main { | |
public static void main(String[] args) { | |
HashTable<String> hashTable = new HashTable<>(5); // initial size | |
Scanner sc = new Scanner(System.in); |
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
Scanner sc = new Scanner(System.in); | |
List<Integer> numbers = Arrays.stream(sc.nextLine().split(" ")) | |
.mapToInt(Integer::parseInt).boxed().collect(Collectors.toList()); | |
int index = sc.nextInt(); | |
if (index < 0) { | |
System.out.println(numbers.get(numbers.size() + index)); | |
} else { | |
System.out.println(numbers.get(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
class Scratch { | |
public static void main(String[] args) { | |
Worker programmer = new Programmer(); | |
Worker carpenter = new Carpenter(); | |
programmer.goToWork(); | |
carpenter.goToWork(); | |
} | |
} |
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 enum DayOfWeek { | |
MONDAY(1,true), | |
TUESDAY(2,true), | |
WEDNESDAY(3,false), | |
THURSDAY(4,false), | |
FRIDAY(5,true), | |
SATURDAY(6,false), | |
SUNDAY(7,true); | |
private final boolean sunny; |
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
class TestDrive { | |
public static void main(String[] args) throws InterruptedException { | |
Phone phone; | |
PhoneFactory iphoneFactory = new IphoneFactory(); | |
PhoneFactory samsungFactory = new SamsungFactory(); | |
System.out.println("-Hello, I need Android phone"); | |
System.out.println("-Okay! Please wait for a sec, - Calling to the SamsungFactory. -Bring me the Samsung Galaxy S10"); | |
Thread.sleep(1500); |
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 javax.imageio.IIOException; | |
import javax.swing.*; | |
import java.io.*; | |
public class HyperSkill { | |
public static void main(String[] args) { | |
Person simon = new Person("simon", 21, new Address("stillwater", "uk")); | |
String fileName = "C:\\users\\si_au\\desktop\\simon.data"; | |
try { |
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
class HashingFun { | |
public static void main(String[] args) throws NoSuchAlgorithmException { | |
MessageDigest hasher = MessageDigest.getInstance("SHA-256"); | |
long count = 0; | |
Random random = new Random(); | |
byte[] data = new byte[258 / 8]; | |
while (true) { |
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.function.*; | |
class FunctionUtils { | |
public static Supplier<Integer> getInfiniteRange() { | |
int[] n = {0}; | |
return new Supplier<Integer>() { | |
@Override | |
public Integer get() { |
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.security.MessageDigest; | |
import java.util.Base64; | |
import java.util.Scanner; | |
import java.util.function.Function; | |
class ChainOfResponsibilityDemo { | |
/** | |
* Accepts a request and returns new request with data wrapped in the tag <transaction>...</transaction> | |
*/ |
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.*; | |
import java.util.stream.LongStream; | |
class Main { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
String name = scanner.nextLine(); | |
Optional<String> optAddress = AddressBook.getAddressByName(name); |