-
-
Save azamsharp/34e45ca7eb18811d3102fcc9fbdfdc71 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
fun main(args :Array<String>) { | |
val names = listOf("Alex","Mary","John") | |
println(names.toBulletList()) | |
val numbers = listOf(3,4,5,12,67,8) | |
println(numbers.toBulletList()) | |
} | |
fun List<Any>.toBulletList() :String { | |
val separator = "\n - " | |
return this.map { "$it" }.joinToString(separator = separator, prefix = separator) | |
} | |
import java.util.* | |
fun main(args :Array<String>) { | |
val numbers = mutableListOf(13,4,5,12,67,8,3) | |
val names = mutableListOf("Alex","Mary","John") | |
sort(numbers) | |
println(numbers) | |
sort(names) | |
println(names) | |
} | |
fun <T> sort(list :MutableList<T>) where T:Comparable<T> { | |
for(i in 0 until list.size) { | |
for(j in 0 until list.size) { | |
if(list[i] < list[j]) { | |
// swap values | |
val temp = list[i] | |
list[i] = list[j] | |
list[j] = temp | |
} | |
} | |
} | |
} | |
/* | |
fun sort(list :MutableList<Int>) { | |
for(i in 0 until list.size) { | |
for(j in 0 until list.size) { | |
if(list[i] < list[j]) { | |
// swap values | |
val temp = list[i] | |
list[i] = list[j] | |
list[j] = temp | |
} | |
} | |
} | |
} */ | |
fun List<Any>.toBulletList() :String { | |
val separator = "\n - " | |
return this.map { "$it" }.joinToString(separator = separator, prefix = separator) | |
} | |
import java.util.* | |
fun main(args :Array<String>) { | |
val numbers = mutableListOf(13,4,5,12,67,8,3) | |
val names = mutableListOf("Alex","Mary","John") | |
sort(numbers) | |
println(numbers) | |
sort(names) | |
println(names) | |
var inputA = 10 | |
var inputB = 5 | |
var (a,b) = swap(inputA,inputB) | |
println("a is $a and b is $b") | |
} | |
fun swap(inputA :Int, inputB:Int) :Pair<Int,Int> { | |
return Pair(inputB, inputA) | |
/* | |
var a = inputA | |
var b = inputB | |
val temp = a | |
a = b | |
b = temp | |
return Pair(a,b) */ | |
} | |
fun <T> sort(list :MutableList<T>) where T:Comparable<T> { | |
for(i in 0 until list.size) { | |
for(j in 0 until list.size) { | |
if(list[i] < list[j]) { | |
// swap values | |
val temp = list[i] | |
list[i] = list[j] | |
list[j] = temp | |
} | |
} | |
} | |
} | |
/* | |
fun sort(list :MutableList<Int>) { | |
for(i in 0 until list.size) { | |
for(j in 0 until list.size) { | |
if(list[i] < list[j]) { | |
// swap values | |
val temp = list[i] | |
list[i] = list[j] | |
list[j] = temp | |
} | |
} | |
} | |
} */ | |
fun List<Any>.toBulletList() :String { | |
val separator = "\n - " | |
return this.map { "$it" }.joinToString(separator = separator, prefix = separator) | |
} | |
import java.util.* | |
fun main(args :Array<String>) { | |
println(divideIfWhole(10,3)) | |
} | |
fun divideIfWhole(value: Int, divisor: Int) :Int? { | |
val quotient = value / divisor | |
val remainder = value % divisor | |
return if(remainder == 0) quotient else null | |
} | |
import java.util.* | |
fun main(args :Array<String>) { | |
for(day in DaysOfTheWeek.values()) { | |
println("${day.name} is ${day.isWeekened}") | |
} | |
} | |
enum class DaysOfTheWeek(var isWeekened :Boolean) { | |
Sunday(true), | |
Monday(false), | |
Tuesday(false), | |
Wednesday(false), | |
Thursday(false), | |
Friday(false), | |
Saturday(true) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment