-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConditionalExpression6.kt
83 lines (69 loc) · 1.03 KB
/
ConditionalExpression6.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#1 /*if can be used as a if expression*/
fun maxOf(a:Int,b:Int):Int
{
if(a<b)
{
println("Kotlin")
}
else
{
println("Programming")
}
}
fun main()
{
println("The Number are ${maxOf(12,13)}")
}
#2 /* Second method*/
fun maxOf(a:Int,b:Int)= if(a<b) a else b
fun main(){
println("The Number are ${maxOf(12,11}")
}
#3 /* For Loop*/
var items = ("apple","banana","grapes")
for(item in items)
{
println(item)
}
#4 /* while loop */
var item = listOf("apple","banana","grapes")
val index = 0
while(item<index)
{
println("The Number are ${item.index}")
index++
}
#5 When Expression
for describe(obj : Any): String = when(obj)
{
1 -> "Hello"
2 -> "World"
else -> "unknown"
}
fun main()
{
println(describe(1))
println(describe(2))
}
#6 For Range Expression
fun main()
{
val x = 10
val y = 11
for (x in 1..10)
{
println(x)
}
}
fun main()
{
val x = 9
val y = 8
if(x==y)
{
println("x equal to y")
}
else
{
println("x is not equal to y")
}