Skip to content

Commit

Permalink
add scanner example
Browse files Browse the repository at this point in the history
  • Loading branch information
indramahkota committed Dec 7, 2021
1 parent 1316d1d commit ad4871a
Show file tree
Hide file tree
Showing 9 changed files with 309 additions and 6 deletions.
17 changes: 17 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions .ipynb_checkpoints/First Kotlin Jupyter-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"id": "5cb815f0",
"metadata": {},
"outputs": [],
"source": [
"class Greeter(private val name: String) {\n",
" // fun greet() = \"Hello, $name!\"\n",
" \n",
" fun greet(): String {\n",
" return \"Hello, $name!\"\n",
" }\n",
Expand All @@ -16,7 +18,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 7,
"id": "b3839e10",
"metadata": {
"scrolled": false
Expand All @@ -28,14 +30,22 @@
"Hello, Jupyter!"
]
},
"execution_count": 4,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Greeter(\"Jupyter\").greet()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "24b279da",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
101 changes: 101 additions & 0 deletions .ipynb_checkpoints/Scanner-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "1c887c75",
"metadata": {},
"source": [
"### Scanner"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "ce81651c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"stdin:1 2 3\n",
"Angka pertama: 1\n",
"Angka kedua: 2\n",
"Angka ketiga: 3\n"
]
}
],
"source": [
"import java.util.Scanner\n",
"\n",
"val scan = Scanner(System.`in`)\n",
"val a = scan.next().trim().toInt()\n",
"val b = scan.next().trim().toInt()\n",
"val c = scan.next().trim().toInt()\n",
"\n",
"println(\"Angka pertama: $a\")\n",
"println(\"Angka kedua: $b\")\n",
"println(\"Angka ketiga: $c\")"
]
},
{
"cell_type": "markdown",
"id": "0d76f97c",
"metadata": {},
"source": [
"### Output Formatting"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "ac70f985",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"================================\n",
"stdin:Apel 2 Semangka 3 Jambu 4\n",
": Apel 002\n",
": Semangka 003\n",
": Jambu 004\n",
"================================\n"
]
}
],
"source": [
"val sc = Scanner(System.`in`)\n",
"println(\"================================\")\n",
"for (i in 0..2) {\n",
" val key: String = sc.next()\n",
" val value: Int = sc.nextInt()\n",
" System.out.printf(\"%-15s : %03d\\n\", key, value)\n",
"}\n",
"println(\"================================\")\n",
"sc.close()\n",
"\n",
"//Input: Apel 2 Semangka 3 Jambu 4"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Kotlin",
"language": "kotlin",
"name": "kotlin"
},
"language_info": {
"codemirror_mode": "text/x-kotlin",
"file_extension": ".kt",
"mimetype": "text/x-kotlin",
"name": "kotlin",
"nbconvert_exporter": "",
"pygments_lexer": "kotlin",
"version": "1.6.20-dev-5432"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
16 changes: 13 additions & 3 deletions First Kotlin Jupyter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"id": "5cb815f0",
"metadata": {},
"outputs": [],
"source": [
"class Greeter(private val name: String) {\n",
" // fun greet() = \"Hello, $name!\"\n",
" \n",
" fun greet(): String {\n",
" return \"Hello, $name!\"\n",
" }\n",
Expand All @@ -16,7 +18,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 7,
"id": "b3839e10",
"metadata": {
"scrolled": false
Expand All @@ -28,14 +30,22 @@
"Hello, Jupyter!"
]
},
"execution_count": 4,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Greeter(\"Jupyter\").greet()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "24b279da",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
101 changes: 101 additions & 0 deletions Scanner.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "c1de3f75",
"metadata": {},
"source": [
"### Scanner"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "af5d9b62",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"stdin:1 2 3\n",
"Angka pertama: 1\n",
"Angka kedua: 2\n",
"Angka ketiga: 3\n"
]
}
],
"source": [
"import java.util.Scanner\n",
"\n",
"val scan = Scanner(System.`in`)\n",
"val a = scan.next().trim().toInt()\n",
"val b = scan.next().trim().toInt()\n",
"val c = scan.next().trim().toInt()\n",
"\n",
"println(\"Angka pertama: $a\")\n",
"println(\"Angka kedua: $b\")\n",
"println(\"Angka ketiga: $c\")"
]
},
{
"cell_type": "markdown",
"id": "f42199cd",
"metadata": {},
"source": [
"### Output Formatting"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "6d54bf9f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"================================\n",
"stdin:Apel 2 Semangka 3 Jambu 4\n",
"Apel : 002\n",
"Semangka : 003\n",
"Jambu : 004\n",
"================================\n"
]
}
],
"source": [
"val sc = Scanner(System.`in`)\n",
"println(\"================================\")\n",
"for (i in 0..2) {\n",
" val key: String = sc.next()\n",
" val value: Int = sc.nextInt()\n",
" System.out.printf(\"%-15s : %03d\\n\", key, value)\n",
"}\n",
"println(\"================================\")\n",
"sc.close()\n",
"\n",
"//Input: Apel 2 Semangka 3 Jambu 4"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Kotlin",
"language": "kotlin",
"name": "kotlin"
},
"language_info": {
"codemirror_mode": "text/x-kotlin",
"file_extension": ".kt",
"mimetype": "text/x-kotlin",
"name": "kotlin",
"nbconvert_exporter": "",
"pygments_lexer": "kotlin",
"version": "1.6.20-dev-5432"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit ad4871a

Please sign in to comment.