Skip to content

Commit

Permalink
Kotlin Basics
Browse files Browse the repository at this point in the history
  • Loading branch information
smartherd committed Sep 16, 2018
1 parent 2cd3d04 commit d8e78de
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 1 deletion.
124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

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

4 changes: 3 additions & 1 deletion 1_hello_world.kt → src/1_hello_world.kt
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")
}
}
18 changes: 18 additions & 0 deletions src/2_explore_first_app.kt
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)

}
14 changes: 14 additions & 0 deletions src/3_comments.kt
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")
}
19 changes: 19 additions & 0 deletions src/4_variables_data_types.kt
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)
}
17 changes: 17 additions & 0 deletions src/5_kotlin_basics.kt
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 = ""
}
7 changes: 7 additions & 0 deletions src/6_Person.kt
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}")
}
}
10 changes: 10 additions & 0 deletions src/6_kotlin_basics.kt
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()
}
21 changes: 21 additions & 0 deletions src/7_data_types.kt
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)
}

19 changes: 19 additions & 0 deletions src/8_string_interpolation.kt
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
}
28 changes: 28 additions & 0 deletions src/9_ranges.kt
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

}

0 comments on commit d8e78de

Please sign in to comment.