How to concatenate string with integer in Scala

3 Answers

0 votes
val str = "The number is: "
val num = 42

val result = str + num

println(result) 



 
/*
run:

The number is: 42

*/

 



answered Jun 17, 2025 by avibootz
0 votes
val num = 42
val result = s"The number is: $num"

println(result) 


 
/*
run:

The number is: 42

*/

 



answered Jun 17, 2025 by avibootz
0 votes
val str = "The number is: "
val num = 42

val result = str + num.toString

println(result) 



 
/*
run:

The number is: 42

*/

 



answered Jun 17, 2025 by avibootz

Related questions

1 answer 155 views
1 answer 214 views
214 views asked Jun 2, 2021 by avibootz
1 answer 199 views
199 views asked Jun 2, 2021 by avibootz
1 answer 139 views
1 answer 175 views
...