如何以表格或维度格式打印数组?

时间:2017-04-05 09:56:43

标签: scala

实际上这是有效的

 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)

以格式

打印arrray
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

但我需要DIMENSION格式,

1 2 3
4 5 6
7 8 9

2 个答案:

答案 0 :(得分:3)

以下内容,

$('.sliderMain').on('afterChange', function(event, slick, currentSlide){ 
  if (currentSlide == 5) { 
    $('.sliderMain').slick('slickPause'); myVideo.play(); 
  } 
});

将打印您的尺寸格式,

val a = Array(Array(1, 2, 3), Array(4, 5, 6), Array(7, 8, 9))

a.foreach(row => println(row.mkString(" ")))

答案 1 :(得分:0)

主题的微小变化

val a = Array(Array(1, 2, 3), Array(4, 5, 6), Array(7, 8, 9))

println(a.map(_.mkString(" ")).mkString("\n"))