I like GAel solution, but to come up with something different, If you're just starting with Scala 3, stick to the traditional main method (def main(args: Array[String]): Unit) or use the simpler @main approach with explicit arguments (@main def addNumbers(arg1: String, arg2: String): Unit).
If you want to access args as Array[String], you should define the main method without the @main annotation:
object AddNumbers {
def main(args: Array[String]): Unit = {
if (args.length < 2) {
println("Please provide two numbers as arguments.")
} else {
println(args(0).toDouble + args(1).toDouble)
}
}
}
You can run this program with command-line arguments, and args will hold all arguments in an array.