其他分享
首页 > 其他分享> > scala多种杨辉三角简洁输出方式

scala多种杨辉三角简洁输出方式

作者:互联网

package com.li.chapter04

object Test04_Practice_Pyramid {
  def main(args: Array[String]): Unit = {
    for (i <- 1 to 9){
      val stars = 2 * i - 1
      val spaces = 9 - i
      println(" " * spaces + "*" * stars)
    }

    for (i <- 1 to 9; stars = 2 * i - 1; spaces = 9 - i){
      println(" " * spaces + "*" * stars)
    }

    for (stars <- 1 to 17 by 2; spaces = (17 - stars) / 2){
      println(" " * spaces + "*" * stars)
    }

    for(i <- 1 to 9 ; j = " "* (9 - i) + "*"*(i*2-1)){
      println(j)
    }
  }
}
D:\Java\jdk1.8.0_202\bin\java.exe "-javaagent:D:\JetBrains\IntelliJ IDEA 2021.2.2\lib\idea_rt.jar=62558:D:\JetBrains\IntelliJ IDEA 2021.2.2\bin" -Dfile.encoding=UTF-8 -classpath D:\Java\jdk1.8.0_202\jre\lib\charsets.jar;D:\Java\jdk1.8.0_202\jre\lib\deploy.jar;D:\Java\jdk1.8.0_202\jre\lib\ext\access-bridge-64.jar;D:\Java\jdk1.8.0_202\jre\lib\ext\cldrdata.jar;D:\Java\jdk1.8.0_202\jre\lib\ext\dnsns.jar;D:\Java\jdk1.8.0_202\jre\lib\ext\jaccess.jar;D:\Java\jdk1.8.0_202\jre\lib\ext\jfxrt.jar;D:\Java\jdk1.8.0_202\jre\lib\ext\localedata.jar;D:\Java\jdk1.8.0_202\jre\lib\ext\nashorn.jar;D:\Java\jdk1.8.0_202\jre\lib\ext\sunec.jar;D:\Java\jdk1.8.0_202\jre\lib\ext\sunjce_provider.jar;D:\Java\jdk1.8.0_202\jre\lib\ext\sunmscapi.jar;D:\Java\jdk1.8.0_202\jre\lib\ext\sunpkcs11.jar;D:\Java\jdk1.8.0_202\jre\lib\ext\zipfs.jar;D:\Java\jdk1.8.0_202\jre\lib\javaws.jar;D:\Java\jdk1.8.0_202\jre\lib\jce.jar;D:\Java\jdk1.8.0_202\jre\lib\jfr.jar;D:\Java\jdk1.8.0_202\jre\lib\jfxswt.jar;D:\Java\jdk1.8.0_202\jre\lib\jsse.jar;D:\Java\jdk1.8.0_202\jre\lib\management-agent.jar;D:\Java\jdk1.8.0_202\jre\lib\plugin.jar;D:\Java\jdk1.8.0_202\jre\lib\resources.jar;D:\Java\jdk1.8.0_202\jre\lib\rt.jar;E:\IdeaWorkspace_Java\scala_course\001_scala\target\classes;D:\tools\Scala\scala-2.12.11\lib\scala-library.jar;D:\tools\Scala\scala-2.12.11\lib\scala-reflect.jar com.li.chapter04.Test04_Practice_Pyramid
        *
       ***
      *****
     *******
    *********
   ***********
  *************
 ***************
*****************
        *
       ***
      *****
     *******
    *********
   ***********
  *************
 ***************
*****************
        *
       ***
      *****
     *******
    *********
   ***********
  *************
 ***************
*****************
        *
       ***
      *****
     *******
    *********
   ***********
  *************
 ***************
*****************

标签:jdk1.8,简洁,Java,lib,scala,jar,jre,202,杨辉三角
来源: https://blog.csdn.net/qq_43900956/article/details/121834201