add examples in java 8 (#12)

* code for chapters 3-9 in Java

* code for chapters 1 in Java

* code for chapter 2 in Java

* missing CheckVoter for chapter 5 in Java

* add missing sample output for SetCovering as a comment
This commit is contained in:
Oleh Novikov
2017-03-20 17:06:45 +01:00
committed by Aditya Bhargava
parent 12265a8c61
commit 4631b7a156
17 changed files with 502 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
public class Countdown {
private static void countdown(int i) {
System.out.println(i);
// base case
if (i <= 0) {
return;
} else {
countdown(i - 1);
}
}
public static void main(String[] args) {
countdown(5);
}
}

View File

@@ -0,0 +1,21 @@
public class Greet {
private static void greet2(String name) {
System.out.println("how are you, " + name + "?");
}
private static void bye() {
System.out.println("ok bye!");
}
private static void greet(String name) {
System.out.println("hello, " + name + "!");
greet2(name);
System.out.println("getting ready to say bye...");
bye();
}
public static void main(String[] args) {
greet("adit");
}
}

View File

@@ -0,0 +1,14 @@
public class Factorial {
private static int fact(int x) {
if (x == 1) {
return 1;
} else {
return x * fact(x - 1);
}
}
public static void main(String[] args) {
System.out.println(fact(5));
}
}