gpt4 book ai didi

indexing - 戈朗 : int to slice conversion

转载 作者:数据小太阳 更新时间:2023-10-29 03:42:34 25 4
gpt4 key购买 nike

完全是 golang(和编程)菜鸟!

给定任何六位数字,如何输出一个 slice ,其中该数字的每个字符都被分配到 slice 中的一个单独位置?

例如,一个包含所有这些字符的 slice (我们称之为 s)将具有 s[0]=第一个数字、s[1]=第二个数字、s[2]=第三个数字等等。

如有任何帮助,我们将不胜感激!

最佳答案

func IntToSlice(n int64, sequence []int64) []int64 {
if n != 0 {
i := n % 10
// sequence = append(sequence, i) // reverse order output
sequence = append([]int64{i}, sequence...)
return IntToSlice(n/10, sequence)
}
return sequence
}

关于indexing - 戈朗 : int to slice conversion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32790681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com