当前位置:网站首页>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))
}
}
边栏推荐
- 2021-01-29
- js图片分辨率压缩
- LeetCode_ Backtracking_ Dynamic programming_ Medium_ 131. split palindrome string
- Array and string offset access syntax with curly braces is no longer support
- Using the hbuilder x editor to install a solution for terminal window plug-ins that are not responding
- China Mobile's mobile phone users grow slowly, but strive for high profit 5g package users
- Longest word in output string
- Spark SQL Start(2.4.3)
- OJ每日一练—— 班级就餐
- Spark RDD Programming Guide(2.4.3)
猜你喜欢

【ARM】讯为rk3568开发板lvds屏设置横屏显示

2021-04-14

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

China Mobile's mobile phone users grow slowly, but strive for high profit 5g package users

2021-08-21

数据库访问工具简介

2021-03-06

ArcGIS application (20) the ArcGIS grid image symbol system prompts "this dataset does not have valid histogram required for classificati..."

2021-08-22

口令安全是什么意思?等保2.0政策中口令安全标准条款有哪些?
随机推荐
Which securities company is the safest and best choice for stock trading account opening
WebRTC系列-网络传输之4Connection排序
Help customers' digital transformation and build a new operation and maintenance system
Introduction and example application of PostgreSQL string separator function (regexp\u split\u to\u table)
DML:Data Manipulation Language 数据操纵语言
Summary of transport layer knowledge points
OJ每日一练——整理命名
Relationship between adau1452 development system interface and code data
同步电路与跨时钟域电路设计2——多bit信号的跨时钟域传输(FIFO)
获取鼠标移动的方向
【22暑期复建1】 Codeforces Round #791 (Div. 2)
2021-08-26
JSBridge
Spark SQL Start(2.4.3)
Tianyi cloud takes advantage of the new infrastructure to build a "4+2" capability system for digital transformation
Digital data was invited to participate in Nantong enterprise digital transformation Seminar
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
OJ每日一练——跨越2020
flutter外包,承接flutter项目
【STM32技巧】使用STM32 HAL库的硬件I2C驱动RX8025T实时时钟芯片