Go 语言打印矩形星形图案程序

编写一个 Go 语言程序来打印矩形星形图案。在此 Golang 矩形星形图案示例中,嵌套的 for 循环迭代矩形的行和列并打印星形。

package main

import "fmt"

func main() {

    var i, j, row, col int

    fmt.Print("Enter the Rectangle Rows = ")
    fmt.Scanln(&row)

    fmt.Print("Enter the Rectangle Columns = ")
    fmt.Scanln(&col)

    fmt.Println("Rectangle Star Pattern")
    for i = 0; i < row; i++ {
        for j = 0; j < col; j++ {
            fmt.Print("* ")
        }
        fmt.Println()
    }
}
Go Program to Print Rectangle Star Pattern

此 Golang 程序允许输入任何符号,并打印该符号的矩形图案。

package main

import "fmt"

func main() {

    var i, j, row, col int
    var sym string

    fmt.Print("Enter the Rectangle Rows = ")
    fmt.Scanln(&row)

    fmt.Print("Enter the Rectangle Columns = ")
    fmt.Scanln(&col)

    fmt.Print("Symbol to Print as Rectangle = ")
    fmt.Scanln(&sym)

    fmt.Println("Rectangle Pattern")
    for i = 0; i < row; i++ {
        for j = 0; j < col; j++ {
            fmt.Printf("%s ", sym)
        }
        fmt.Println()
    }
}
Enter the Rectangle Rows = 7
Enter the Rectangle Columns = 20
Symbol to Print as Rectangle = $
Rectangle Pattern
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $