diff --git a/functions/functions.iml b/functions/functions.iml new file mode 100644 index 0000000..4fd7bdb --- /dev/null +++ b/functions/functions.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/functions/src/Main.kt b/functions/src/Main.kt new file mode 100644 index 0000000..7265465 --- /dev/null +++ b/functions/src/Main.kt @@ -0,0 +1,14 @@ +//TIP To Run code, press or +// click the icon in the gutter. +fun main() { + val name = "Kotlin" + //TIP Press with your caret at the highlighted text + // to see how IntelliJ IDEA suggests fixing it. + println("Hello, " + name + "!") + + for (i in 1..5) { + //TIP Press to start debugging your code. We have set one breakpoint + // for you, but you can always add more by pressing . + println("i = $i") + } +} \ No newline at end of file diff --git a/functions/src/default_parameter.kt b/functions/src/default_parameter.kt new file mode 100644 index 0000000..c6bbcff --- /dev/null +++ b/functions/src/default_parameter.kt @@ -0,0 +1,10 @@ +fun startCamelRide (time: Int = 5, speed: Int = 5) { + val distance = time * speed + println ("Distance: $distance km, Time: $time hours, Speed: $speed km/h") + +} + +fun main () { + startCamelRide(2, 10) + startCamelRide(3) +} \ No newline at end of file diff --git a/functions/src/multiple_parameter.kt b/functions/src/multiple_parameter.kt new file mode 100644 index 0000000..a923f7c --- /dev/null +++ b/functions/src/multiple_parameter.kt @@ -0,0 +1,9 @@ +fun findOasis (x: Int, y: Int): String { + return "Oasis found at coordinates ($x, $y)" +} + +fun main () { + val result = findOasis(10, 20) + println(result) +} + diff --git a/functions/src/named_arguments.kt b/functions/src/named_arguments.kt new file mode 100644 index 0000000..cfb14e0 --- /dev/null +++ b/functions/src/named_arguments.kt @@ -0,0 +1,10 @@ +fun exploreDune(height: Int, climbRate: Int) { + val timeRequired = height.toDouble() / climbRate + println("Time to Climb the Dune: $timeRequired hours") +} + +fun main() { + + exploreDune(climbRate = 3, height = 20) + +} \ No newline at end of file diff --git a/functions/src/no_parameter.kt b/functions/src/no_parameter.kt new file mode 100644 index 0000000..e07a2b2 --- /dev/null +++ b/functions/src/no_parameter.kt @@ -0,0 +1,7 @@ +fun greetTraveler() { + println("Welcome to the Desert, Traveler!") +} + +fun main() { + greetTraveler() +} diff --git a/functions/src/return_function.kt b/functions/src/return_function.kt new file mode 100644 index 0000000..dfd8b51 --- /dev/null +++ b/functions/src/return_function.kt @@ -0,0 +1,8 @@ +fun currentTemperature (morningTemperature: Int, afternoonTemperature: Int): Int { + return (morningTemperature + afternoonTemperature) / 2 +} + +fun main() { + val averageTemp = currentTemperature(25, 40) + println("Average temperature for the day: $averageTemp°C") +} \ No newline at end of file diff --git a/functions/src/single_expression.kt b/functions/src/single_expression.kt new file mode 100644 index 0000000..335f577 --- /dev/null +++ b/functions/src/single_expression.kt @@ -0,0 +1,7 @@ +fun survivalChance(supplies: Int) = supplies * 10 + +fun main() { + + val chance = survivalChance(8) + println("Survival Chance: $chance") +}