dqh19413 2019-08-24 12:33
浏览 8

使用GolLand时无法在CMD终端上运行同一程序,但运行正常

When I am using GoLand to run my program, everything works fine, just like what I expected. But, my program does not work well when I try to manually run it in CMD terminal.

The command line I used to run my program was "go run c.go" where c.go is my source file.

Here is the correct result from GoLand:

enter image description here

Where the green numbers are the inputs from stdin.

Meanwhile with the terminal:

enter image description here

The program failed after I input "-1" into stdin.

Here is the code:

func IterElements(numElement int, elements []string) int {
if numElement == 0 {
    return 0
}

//********************************

var e = elements[0] //Line 22

//********************************

number, err := strconv.Atoi(e)
if err != nil {
    //fmt.Println(err)
    //os.Exit(2)
}

numElement--
if number<0{
    return IterElements(numElement, elements[1:])
}else {
    return number*number + IterElements(numElement, elements[1:])
}}

It converts a string from elements-array to an integer and calculates its square, and sum the squared numbers iteratively.

Any help? Thank you!

Update: Full Code in Playground

https://play.golang.org/p/0ksctGHWM1R

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥16 mybatis的代理对象无法通过@Autowired装填
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示
    • ¥15 求三国群英传pl国战时间的修改方法
    • ¥15 matlab代码代写,需写出详细代码,代价私
    • ¥15 ROS系统搭建请教(跨境电商用途)
    • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。