当前位置:网站首页>os. When the command line parameter in args[1:] is empty, the internal statement will not be executed
os. When the command line parameter in args[1:] is empty, the internal statement will not be executed
2022-06-22 23:23:00 【Jimmy_ jimi】
Problem description
When the value entered on the command line is null , Not execute else Statement block after .
func qualityTran() {
for _,v := range os.Args[1:]{
// If it's not empty , Direct conversion to original value
if v !=""{
a,_ := strconv.Atoi(v)
fmt.Println(tran(a))
//input.Scan()
}else {
fmt.Println("1")
// If it is empty, it is read from the standard input
fmt.Println("please input a num:")
input := bufio.NewScanner(os.Stdin)
input.Scan()
a :=input.Text()
b,_ := strconv.Atoi(a)
fmt.Println(tran(b))
}
}
}
Cause analysis :
During the actual program execution ,for The cycle ends directly , Will not enter if Sentence judgment .
Solution :
func qualityTran() {
flag :=0
for _,v := range os.Args[1:]{
// If it's not empty , Direct conversion to original value
if v !=""{
a,_ := strconv.Atoi(v)
fmt.Println(tran(a))
//input.Scan()
flag =1
}
}
if flag ==0 {
// If it is empty, it is read from the standard input
fmt.Println("please input a num:")
input := bufio.NewScanner(os.Stdin)
input.Scan()
a :=input.Text()
b,_ := strconv.Atoi(a)
fmt.Println(tran(b))
}
}
边栏推荐
- How to change the dial on the apple Watch
- 2021-08-21
- Finding the value of the nth term of Fibonacci sequence by recursion
- web缓存技术
- 别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
- 2021-08-21
- Autoincrement attribute of sqlserver replication table
- A spark app demo
- 斐波那契数列合集
- Array and string offset access syntax with curly braces is no longer support
猜你喜欢

2021-08-26

Install the typescript environment and enable vscode to automatically monitor the compiled TS file as a JS file

Spark RDD Programming Guide(2.4.3)

Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!

2021-03-06

2021-04-16

Smart data won two annual awards at the second isig China Industrial Intelligence Conference

c语言---17 函数简介

异步FIFO

【Kubernetes 系列】Kubernetes 概述
随机推荐
对 cookie 的添加/获取和删除
OJ每日一练——过滤多余的空格
uniapp 修改数组属性,视图不更新
2020-12-04
Phantomjs实用代码段(持续更新中……)
Phantomjs utility code snippet (under continuous update...)
Considerations for using redisson to operate distributed queues
2021-08-22
2020-12-20
Valid parentheses
Mysql database design
【22暑期复建1】 Codeforces Round #791 (Div. 2)
[redisson] source code analysis of multilock
SSH method 2 for adding node nodes in Jenkins
SqlServer 复制表的自增属性
PHP7.3报错undefined function simplexml_load_string()
ArcGIS应用(二十)Arcgis 栅格图像符号系统提示“This dataset does not have valid histogram required for classificati…”
使用smart-doc自动生成接口文档
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
LeetCode_ Backtracking_ Dynamic programming_ Medium_ 131. split palindrome string