Skip to content

Instantly share code, notes, and snippets.

View wsadrak's full-sized avatar
🏠
Working from home

Wojtek wsadrak

🏠
Working from home
  • Kraków, Poland
View GitHub Profile
@wsadrak
wsadrak / factorial-using-recursion.java
Last active February 28, 2019 13:52
Description: Write program to find factorial of a given number using recursion
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
int factArg = readValueFromUser();
int result = calculateFactorial(factArg);
System.out.println("Factorial " + factArg + " = " + result);
}
@wsadrak
wsadrak / PrimeNumbers.java
Created February 28, 2019 12:33
Description: Write program to display prime numbers from 1 to n (entered by user)
import java.util.Scanner;
public class PrimeNumbers {
private static final int START_VALUE = 2;
public static void main(String[] args) {
int n = readValueFromUser();
printPrimeNumbers(n);
}
@wsadrak
wsadrak / multiplication-table.java
Last active February 28, 2019 11:39
Description: Write a program to create a simple, text-based, multiplication table based on user's input.
import java.util.Scanner;
public class MultiplicationTable {
public static void main(String[] args) {
int size = readValueFromUser();
generateTable(size);
}
private static int readValueFromUser() {
System.out.println("Please type a size of multiplication table: ");
@wsadrak
wsadrak / first-1000-prime-numbers.java
Last active February 28, 2019 11:38
Description: Write a program to find the sum of the first 1000 prime numbers.
public class SumOfPrimeNumbers {
private static final int START_VALUE = 2;
private static final int HOW_MANY_PRIME_NUMBERS = 1000;
public static void main(String[] args) {
int currentValue = START_VALUE;
int primeNumbersCounter = 0;
int sumOfPrimeNumbers = 0;
@wsadrak
wsadrak / prime-numbers.java
Last active February 28, 2019 11:37
Description: Write a program to check the given number is a prime number or not.
public class PrimeNumbers {
public static void main(String[] args) {
System.out.println("Is 17 prime number? " + isPrimeNumber(17));
System.out.println("Is 19 prime number? " + isPrimeNumber(19));
System.out.println("Is 15 prime number? " + isPrimeNumber(15));
}
@wsadrak
wsadrak / my-array-list.java
Created February 28, 2019 10:39
Description: Write a program to implement your own ArrayList class. It should contain add(), get(), remove(), size() methods. Use dynamic array logic. It should increase its size when it reaches threshold
import java.util.Arrays;
public class MyArrayList {
private Object[] arrayList = new Object[1];
private int emptyPlace = 0;
public void add(Object object) {
if (emptyPlace == arrayList.length) {
arrayList = Arrays.copyOf(arrayList, arrayList.length * 2);
}