亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何運行循環 3 次?

如何運行循環 3 次?

Go
皈依舞 2022-08-30 21:52:34
任務: You are making a robot that can speak numbers. Your robot should take 3 numbers in the range of 0-10 as input and output the corresponding texts in English.預解決方案:演示func main() {num := 0var input intfor i := 0; i < 10; i++ {    num += 1    switch num {    case 1:        fmt.Println("One")    case 2:        fmt.Println("Two")    case 3:        fmt.Println("Three")    case 4:        fmt.Println("Four")    case 5:        fmt.Println("Five")    case 6:        fmt.Println("Six")    case 7:        fmt.Println("Seven")    case 8:        fmt.Println("Eight")    case 9:        fmt.Println("Nine")    case 10:        fmt.Println("Ten")    }}}問題:如何運行循環 3 次?更多詳情: https://www.sololearn.com/learning/eom-project/1164/1188
查看完整描述

2 回答

?
翻閱古今

TA貢獻1780條經驗 獲得超5個贊

這似乎做到了:


package main

import "fmt"


func robot(d, e, f int) (string, string, string) {

   m := map[int]string{

      0: "zero", 1: "one", 2: "two", 3: "three", 4: "four",

      5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 10: "ten",

   }

   return m[d], m[e], m[f]

}


func main() {

   s, t, u := robot(1, 2, 3)

   fmt.Printf("%q %q %q\n", s, t, u)

}


查看完整回答
反對 回復 2022-08-30
?
largeQ

TA貢獻2039條經驗 獲得超8個贊

該任務指出,您需要使輸入3位數字,輸出應該有文本,我做到了并傳遞了所有


package main


import "fmt"


func main() {


    var input int

    var i = 1

    for {

        fmt.Scanln(&input)

        if input >= 0 && input <= 10 {

            switch input {

            case 0:

                fmt.Println("Zero")

            case 1:

                fmt.Println("One")

            case 2:

                fmt.Println("Two")

            case 3:

                fmt.Println("Three")

            case 4:

                fmt.Println("Four")

            case 5:

                fmt.Println("Five")

            case 6:

                fmt.Println("Six")

            case 7:

                fmt.Println("Seven")

            case 8:

                fmt.Println("Eight")

            case 9:

                fmt.Println("Nine")

            case 10:

                fmt.Println("Ten")

            }

            if i == 3 {

                break

            }

            i++

        }

    }

}


查看完整回答
反對 回復 2022-08-30
  • 2 回答
  • 0 關注
  • 105 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號