0

Actually this works

 object Matrixmul extends App { val a = Array(Array(1, 2, 3), Array(4, 5, 6), Array(7, 8, 9)) val b = Array(Array(1, 2, 3), Array(4, 5, 6), Array(7, 8, 9)) val c = Array.ofDim[Int](3, 3) val sum =Array.ofDim[Int](3,3) println(a.mkString(" ")) val elements = for { row <- a ele <- row }yield ele for(array1 <-elements) println(" the 1st matrix array elements are : " + array1) 

This prints the arrray in the format,

the 1st matrix array elements are : 1 the 1st matrix array elements are : 2 the 1st matrix array elements are : 3 the 1st matrix array elements are : 4 the 1st matrix array elements are : 5 the 1st matrix array elements are : 6 the 1st matrix array elements are : 7 the 1st matrix array elements are : 8 the 1st matrix array elements are : 9 

But I need in DIMENSION format,

1 2 3 4 5 6 7 8 9 
1
  • [1 2 3] [4 5 6] [7 8 9] in matrix format Commented Apr 5, 2017 at 9:57

2 Answers 2

3

How about the following,

val a = Array(Array(1, 2, 3), Array(4, 5, 6), Array(7, 8, 9)) a.foreach(row => println(row.mkString(" "))) 

Which will print your dimentional format,

1 2 3 4 5 6 7 8 9 
Sign up to request clarification or add additional context in comments.

1 Comment

YES , It works. Thanks for the solution. EVEN this also works println(" The 1 st ARRAY MATRIX ARE : " + "\n"+ a.deep.mkString(" \t \n"))
0

Small variation on the subject

val a = Array(Array(1, 2, 3), Array(4, 5, 6), Array(7, 8, 9)) println(a.map(_.mkString(" ")).mkString("\n")) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.