From 22eb872c0aa3922719fc7c6077c278a8a1ae4c73 Mon Sep 17 00:00:00 2001 From: Naufal Rachmandani <5174397-NaufalRachmandani@users.noreply.gitlab.com> Date: Sat, 9 Oct 2021 02:20:05 +0700 Subject: [PATCH] Q2. Write a program to plus and minus with sample of extension function from kotlin --- .idea/.gitignore | 3 +++ kotlin/Program2/README.md | 1 + kotlin/Program2/extension.kt | 15 +++++++++++++++ kotlin/README.md | 1 + 4 files changed, 20 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 kotlin/Program2/README.md create mode 100644 kotlin/Program2/extension.kt diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/kotlin/Program2/README.md b/kotlin/Program2/README.md new file mode 100644 index 00000000..2de265c9 --- /dev/null +++ b/kotlin/Program2/README.md @@ -0,0 +1 @@ +Q2. Write a program to plus and minus with sample of extension function from kotlin diff --git a/kotlin/Program2/extension.kt b/kotlin/Program2/extension.kt new file mode 100644 index 00000000..30593f4e --- /dev/null +++ b/kotlin/Program2/extension.kt @@ -0,0 +1,15 @@ +fun main(args: Array) { + println("Basic Extension Function") + val plus = 2.plusNumber(2) + val minus = 2.minusNumber(2) + println("2 + 2 : $plus") + println("2 - 2 : $minus") +} + +fun Int.plusNumber(number: Int): Int { + return this + number +} + +fun Int.minusNumber(number: Int): Int { + return this - number +} \ No newline at end of file diff --git a/kotlin/README.md b/kotlin/README.md index 282dd5fa..73c15c50 100644 --- a/kotlin/README.md +++ b/kotlin/README.md @@ -4,5 +4,6 @@ | Program No.| Question | | ------- | ------ | | [Program-1](https://github.com/swaaz/basicprograms/blob/814a1e60ae23d81158d8174666f23c9b7419e15e/kotlin/Program1/pattern.kt) | Write a program to print half pyramid using ' * ' +| [Program-2](https://github.com/swaaz/basicprograms/blob/814a1e60ae23d81158d8174666f23c9b7419e15e/kotlin/Program2/extension.kt) | Q2. Write a program to plus and minus with sample of extension function from kotlin