Add a beautiful code :)

This commit is contained in:
2022-03-26 14:34:18 +01:00
parent efb97b91cf
commit dc16b00d54
2 changed files with 43 additions and 5 deletions

View File

@@ -1,7 +1,39 @@
fun main(args: Array<String>) {
println("Hello World!")
// Try adding program arguments via Run/Debug configuration.
// Learn more about running applications: https://www.jetbrains.com/help/idea/running-applications.html.
println("Program arguments: ${args.joinToString()}")
fun main() {
var x: Int? = null;
var y: Int? = null;
var min: Int? = null;
var max: Int? = null;
try {
print("X = ");
x = readLine()?.toInt()
print("Y = ");
y = readLine()?.toInt()
print("Min = ");
min = readLine()?.toInt()
print("Max = ");
max = readLine()?.toInt()
} catch (_: NumberFormatException) {}
if(x != null && y != null && max != null && min != null && min <= max) {
val strings = List(max - min) { // Creo la lista utilizzando lambda expression
val n = it+min // it rappresenta l'indice della lista che sto inizializzando, il numero corrispondente è quindi it+min
if(n % x == 0) {
"Cip"
} else if(n % y == 0) {
"Ciop"
} else {
n
}
}
println(strings)
} else {
println("Input non valido")
}
}