here is my code:
object theater extends App { val m = readInt val n = readInt val a = readInt val c1 = m/a + (if(m%a == 0) 0 else 1) val c2 = n/a + (if(n%a == 0) 0 else 1) print(c1 + c2) }
But input format: 3 integers in one line. But for 3 integers in one line, scala will consider this as a string. How can I read this line and get 3 values ββin three separated variables?
You can use the following code, which will read the line and use the first three characters separated by spaces as input. (Expects, for example, "1 2 3" as an input on one line)
val Array(m,n,d) = readLine.split(" ").map(_.toInt)
You can use Java.util.Scanner in scala programs. It supports scanner functions available in java
import java.util.Scanner; object Addition{ def main(args: Array[String]){ var scanner = new Scanner(System.in); //defining scanner object println("Enter two numbers : "); var a = scanner.nextInt(); //reading space separated input var b = scanner.nextInt(); println("The result is : "+(a+b)); } }