Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephan Oudmaijer soudmaijer

View GitHub Profile
View Exercise14.kt
fun main() {
val product = Product()
val book1 = Book(ean = "9780671628314")
val book2 = Book(ean = "9781617293290", title = "Kotlin in Action")
}
View Exercise13.kt
fun main() {
val students = listOf(
Student("John", 19, "UK"),
Student("Clair", 16, "US"),
Student("Linda", 21, "NL"),
Student("Jan", 14, "NL")
)
}
View Exercise12.kt
fun printLength(str: String?) {
val length: Int = str.length
print("$str length is $length")
}
View Exercise11.kt
fun main() {
val houseNumber = "121"
val nextHouseNumber = houseNumber + 1
println(nextHouseNumber) // should print 122
}
View Loops.java
import java.util.List;
public class Loops {
public static void main(String[] args) {
List<String> list = List.of("a", "b");
for (String s : list) {
System.out.println(s);
}
View IfWhen.java
public class IfWhen {
public static boolean yesNoToBoolean(String s) {
if ("yes".equals(s)) return true;
else if ("no".equals(s)) return false;
else throw new RuntimeException("Unsupported value: " + s);
}
public static void main(String[] args) {
System.out.println(yesNoToBoolean("yes"));
View Variables.kt
fun main(args: Array<String>) {
val name = "Kotlin"
name = "John Doe"
println("Hello, $name!")
var answer = 21
answer = "42"
println("The answer to everything: $answer!")
val groceries = listOf("Bread", "Butter", "Milk")
View Calculator.java
public class Calculator {
public int sum(int a, int b, int c) {
return a + b + c;
}
public static void main(String[] args) {
Calculator f = new Calculator();
System.out.println(f.sum(0, 1, 2));
}
View CallFoo.java
public class CallFoo {
public static void main(String[] args) {
Utils.foo();
}
}
View Person.java
public class Person {
private final String name;
private final int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {