scala案例-- 九九乘法表

admin2024-05-15  0

要求:打出九九乘法表

object test {
  def main(args: Array[String]): Unit = {
    for (i <- 1 to 9) {    //外循环控制行数
      for (j <- 1 to i) {   //内循环控制列数
        print(s"${j} * ${i} = ${i + j}\t")
      }
      println()
    }

  }
}

结果:

1 * 1 = 2	
1 * 2 = 3	2 * 2 = 4	
1 * 3 = 4	2 * 3 = 5	3 * 3 = 6	
1 * 4 = 5	2 * 4 = 6	3 * 4 = 7	4 * 4 = 8	
1 * 5 = 6	2 * 5 = 7	3 * 5 = 8	4 * 5 = 9	5 * 5 = 10	
1 * 6 = 7	2 * 6 = 8	3 * 6 = 9	4 * 6 = 10	5 * 6 = 11	6 * 6 = 12	
1 * 7 = 8	2 * 7 = 9	3 * 7 = 10	4 * 7 = 11	5 * 7 = 12	6 * 7 = 13	7 * 7 = 14	
1 * 8 = 9	2 * 8 = 10	3 * 8 = 11	4 * 8 = 12	5 * 8 = 13	6 * 8 = 14	7 * 8 = 15	8 * 8 = 16	
1 * 9 = 10	2 * 9 = 11	3 * 9 = 12	4 * 9 = 13	5 * 9 = 14	6 * 9 = 15	7 * 9 = 16	8 * 9 = 17	9 * 9 = 18	
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明原文出处。如若内容造成侵权/违法违规/事实不符,请联系SD编程学习网:675289112@qq.com进行投诉反馈,一经查实,立即删除!