qq_39586869
2017-12-06 03:05现在一个计数器一样的功能有个判断不是很明白。。。。。。。
5 //要求是:手动输入字符串输出字符串出现的次数
public static void main(String[] args) {
//获取Scanner
Scanner sc = new Scanner(System.in);
System.out.println("请输入拼音字符,字符和字符中间带空格哦!!");
//这个不是很理解,就是只有获取下一行这么简单吗?
String nextLine = sc.nextLine();
boolean flag = false;
int count = 0;
//对这个nextLine进行一个循环
for(int i =0; i < nextLine.length();i++){
//获取循环出来的字符串
char charAt = nextLine.charAt(i);
//在循环的时候进行判断
//下面是单引号,单引号适用于char双引号适用于String
if(charAt != ' '){
//这块不是很明白,为什么要有if(!false)这个操作?-------------
if(!false){
flag = true;
count++;
}
}else{
flag = false;
}
}
System.out.println(count);
}
下面这是效果图
- 点赞
- 回答
- 收藏
- 复制链接分享
2条回答
为你推荐
- 现在一个计数器一样的功能有个判断不是很明白。。。。。。。
- string
- boolean
- 2个回答