GOLANGPROFI Telegram 257
👣 Как вывести срез (массив) с значениями типа int через запятую?

Ответ

package main

import (
"fmt"
"io"
"os"
)

func FprintArray[T any](w io.Writer, arr []T) {
if len(arr) == 0 {
return
}
fmt.Fprintf(w, "%v", arr[0])
for _, obj := range arr[1:] {
fmt.Fprintf(w, ", %v", obj)
}
}

func main() {
arr := []int{155, 133, 127, 123, 117, 105, 104, 98, 94, 90, 77, 76, 70, 55, 50, 45, 43, 42, 37, 29}
fmt.Print("[")
FprintArray(os.Stdout, arr)
fmt.Println("]")
}

Пишите свое решение в комментариях👇
Please open Telegram to view this post
VIEW IN TELEGRAM
👍3🤔2



tgoop.com/golangprofi/257
Create:
Last Update:

👣 Как вывести срез (массив) с значениями типа int через запятую?

Ответ

package main

import (
"fmt"
"io"
"os"
)

func FprintArray[T any](w io.Writer, arr []T) {
if len(arr) == 0 {
return
}
fmt.Fprintf(w, "%v", arr[0])
for _, obj := range arr[1:] {
fmt.Fprintf(w, ", %v", obj)
}
}

func main() {
arr := []int{155, 133, 127, 123, 117, 105, 104, 98, 94, 90, 77, 76, 70, 55, 50, 45, 43, 42, 37, 29}
fmt.Print("[")
FprintArray(os.Stdout, arr)
fmt.Println("]")
}

Пишите свое решение в комментариях👇

BY Golang Юниор


Share with your friend now:
tgoop.com/golangprofi/257

View MORE
Open in Telegram


Telegram News

Date: |

Activate up to 20 bots Content is editable within two days of publishing 5Telegram Channel avatar size/dimensions In the “Bear Market Screaming Therapy Group” on Telegram, members are only allowed to post voice notes of themselves screaming. Anything else will result in an instant ban from the group, which currently has about 75 members. The Standard Channel
from us


Telegram Golang Юниор
FROM American