-
Notifications
You must be signed in to change notification settings - Fork 0
/
020_arrays.kt
39 lines (31 loc) · 851 Bytes
/
020_arrays.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
fun main(args: Array<String>){
/*val names: Array<String> = arrayOf("Anish", "Shitix", "Rushi")
val numbers: Array<Int> = arrayOf(4,5,6,7)
names[0] = "Abhijeet"
println("First element is ${names[0]}")
println("The size of the array is: ${names.size}")
for(i in numbers){
println()
}*/
val max: Int = findMax(arrayOf(4,5,6,7,8))
val min: Int = findMin(arrayOf(4,5,6,7,8))
println("Max value is $max and Min value is $min")
}
fun findMax(numbers: Array<Int>): Int{
var max: Int = numbers[0]
for(number: Int in numbers){
if(number > max){
max = number
}
}
return max
}
fun findMin(numbers: Array<Int>): Int{
var min: Int = numbers[0]
for(number: Int in numbers){
if(number < min){
min = number
}
}
return min
}