scala输出一个菱形
时间: 2023-03-28 10:03:35 浏览: 115
您好,以下是输出菱形的 Scala 代码:
```
object Main {
def main(args: Array[String]): Unit = {
val n = 5
for (i <- 1 to n) {
for (j <- 1 to n - i) {
print(" ")
}
for (j <- 1 to 2 * i - 1) {
print("*")
}
println()
}
for (i <- n - 1 to 1 by -1) {
for (j <- 1 to n - i) {
print(" ")
}
for (j <- 1 to 2 * i - 1) {
print("*")
}
println()
}
}
}
```
希望能对您有所帮助。
阅读全文