forked from smartherd/KotlinTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
280 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
|
||
// Hello World App | ||
|
||
fun main(args: Array<String>) { | ||
print("Hello World") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
// Explore First App | ||
|
||
fun main(args: Array<String>) { | ||
|
||
println("Hello World") | ||
|
||
println(10) | ||
|
||
println(true) | ||
|
||
println(10 / 2) | ||
|
||
println(94.2f) | ||
|
||
println(9 - 3) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
|
||
|
||
/* | ||
* This is comment line 1 | ||
* | ||
* This is comment line 2 | ||
* | ||
* This is main function. Entry point of the application. | ||
* */ | ||
|
||
fun main(args: Array<String>) { // This is inline comment ... | ||
print("Hello World") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
/* | ||
* This is main function. Entry point of the application. | ||
* */ | ||
fun main(args: Array<String>) { | ||
|
||
var myNumber = 10 // Int | ||
var myDecimal = 1.0 // Float | ||
var isActive = true // Boolean | ||
|
||
var myString: String // Mutable String | ||
myString = "Hello World" | ||
myString = "Another World" | ||
|
||
val myAnotherString = "My constant string value" // Immutable String | ||
// myAnotherString = "some value" // NOT ALLOWED, since it is immutable | ||
|
||
print(myNumber) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
|
||
/* | ||
* This is main function. Entry point of the application. | ||
* */ | ||
fun main(args: Array<String>) { | ||
|
||
var personObj = Person() | ||
personObj.name = "Steve" | ||
|
||
print("The name of the person is ${personObj.name}") | ||
} | ||
|
||
class Person { | ||
|
||
var name: String = "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
class Persson(var name: String ) { | ||
|
||
fun display() { | ||
print("The name of the person is ${name}") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
/* | ||
* This is main function. Entry point of the application. | ||
* */ | ||
fun main(args: Array<String>) { | ||
|
||
var personObj = Persson("Steve") | ||
|
||
personObj.display() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
/* | ||
* Explore Data Types in Kotlin | ||
* */ | ||
|
||
fun main(args: Array<String>) { | ||
|
||
var name: String | ||
name = "Kevin" | ||
|
||
var age: Int = 10 | ||
var myAge = 10 | ||
|
||
var isAlive: Boolean = true | ||
var marks: Float = 97.4F | ||
var percentage: Double = 90.78 | ||
var gender: Char = 'M' | ||
|
||
print(marks) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
/* | ||
* Explore String Interpolation in Kotlin | ||
* */ | ||
fun main(args: Array<String>) { | ||
|
||
var rect = Rectangle() | ||
rect.length = 5 | ||
rect.breadth = 3 | ||
|
||
print("The length of the rectangle is ${rect.length} and breadth is ${rect.breadth}. The area is ${rect.length * rect.breadth}") | ||
|
||
} | ||
|
||
class Rectangle { | ||
|
||
var length: Int = 0 | ||
var breadth: Int = 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
|
||
/* | ||
* Explore Ranges | ||
* */ | ||
fun main(args: Array<String>) { | ||
|
||
var r1 = 1..5 | ||
// This range contains number 1, 2, 3, 4, 5 | ||
|
||
val r2 = 5 downTo 1 | ||
// This range contains number 5, 4, 3, 2, 1 | ||
|
||
val r3 = 5 downTo 1 step 2 | ||
// This range contains number 5, 3, 1 | ||
|
||
val r4 = 'a'..'z' | ||
// This range contains the values from "a", "b", "c" . . . "z" | ||
|
||
var isPresent = 'c' in r4 | ||
|
||
var countDown = 10.downTo(1) | ||
// This range contains number 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 | ||
|
||
var moveUp = 1.rangeTo(10) | ||
// This range contains number 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 | ||
|
||
} |