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

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -1,7 +1,39 @@
fun main(args: Array<String>) {
println("Hello World!")
// Try adding program arguments via Run/Debug configuration. fun main() {
// Learn more about running applications: https://www.jetbrains.com/help/idea/running-applications.html. var x: Int? = null;
println("Program arguments: ${args.joinToString()}") 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")
}
} }