generated from justuser-31/code_projects_template
51 lines
1.3 KiB
Kotlin
51 lines
1.3 KiB
Kotlin
import java.io.File
|
|
|
|
fun main() {
|
|
print("Enter a: "); val a = readln().toInt()
|
|
print("Enter b: "); val b = readln().toInt()
|
|
|
|
// Create matrix
|
|
var matrix: Array<Array<Int>> = Array(2) { Array(2) {0} }
|
|
matrix[0][0] = a ; matrix[1][0] = b
|
|
matrix[0][1] = a + 1; matrix[1][1] = b + 1
|
|
|
|
// Make strings
|
|
var str1: String = "${matrix[0][0]} ${matrix[0][1]}"
|
|
var str2: String = "${matrix[1][0]} ${matrix[1][1]}"
|
|
|
|
// Write result
|
|
val file = File("file")
|
|
file.writeText("""
|
|
$str1
|
|
$str2
|
|
""".trimIndent())
|
|
|
|
// Read result
|
|
var new_matrix: Array<Array<Int>> = Array(2) { Array(2) {0} }
|
|
|
|
val lines: List<String> = file.readLines()
|
|
var first = true
|
|
for (i in lines) {
|
|
if (first) {
|
|
// Convert List<String> -> List<Int> -> Array<Int>
|
|
new_matrix[0] = i.split(" ").map { it.toInt() }.toTypedArray()
|
|
first = false
|
|
}
|
|
else {
|
|
new_matrix[1] = i.split(" ").map { it.toInt() }.toTypedArray()
|
|
}
|
|
}
|
|
|
|
// Get output
|
|
println("""
|
|
Original matrix:
|
|
${matrix[0][0]} ${matrix[0][1]}
|
|
${matrix[1][0]} ${matrix[1][1]}
|
|
|
|
Readed matrix:
|
|
${new_matrix[0][0]} ${new_matrix[0][1]}
|
|
${new_matrix[1][0]} ${new_matrix[1][1]}
|
|
""".trimIndent())
|
|
|
|
}
|