How to get the middle character from a string in Scala

1 Answer

0 votes
object Main extends App {
  val s = "abcdefg"
  
  val index = Math.floor(s.length / 2).toInt
  
  println(s(index))
}


   
/*
           
run:
     
d
       
*/

 



answered Sep 10, 2024 by avibootz
...