Created
October 22, 2022 08:21
-
-
Save gonaumov/51f334f0d04bcd6257273e31120ed3f3 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
package converter | |
fun main() { | |
while (true) { | |
println("Enter two numbers in format: {source base} {target base} (To quit type /exit)") | |
val userChoice = readln() | |
if (userChoice == "/exit") { | |
break; | |
} | |
val conversionBases = userChoice.split("\\s+".toRegex()).map { | |
it.trim().toBigInteger() | |
} | |
check(conversionBases.size == 2) { | |
"You must provide {source base} and {target base}" | |
} | |
val (sourceBase, targetBase) = conversionBases | |
while (true) { | |
println("Enter number in base $sourceBase to convert to base $targetBase (To go back type /back)") | |
val conversionInput = readln().trim().split(".")[0] | |
if (conversionInput.trim().lowercase() == "/back") { | |
break | |
} | |
var numberConverter = NumberConverter(sourceBase, targetBase) | |
println("Conversion result: ${numberConverter.convert(conversionInput.uppercase())}") | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment