scala-第七章-打印9*9乘法口诀表

class multitable{
  def makeRowSeq(row: Int) = 
  for(col <- 1 to 10) yield {
    val prod = (row * col).toString;//prod=行号*列号
    val padding = " " * (4 - prod.length);//添加padding个空格
    padding + prod
  }
  def makeRow(row: Int) = makeRowSeq(row).mkString;
  def multiTable() = {
    val tableSeq = 
      for(row <- 1 to 10)
        yield makeRow(row)
    tableSeq.mkString("\n");
  }
}

你可能感兴趣的:(scala-第七章-打印9*9乘法口诀表)