2015年11月15日

来源:互联网 发布:淘宝连帽 编辑:程序博客网 时间:2024/06/06 09:02
好久没做杭电了,2017,也是很简单的 。这里就是next()与nextLine()的区别 。
import java.util.Scanner;
class Main{
  public static void main(Stringargs[]){
  Scanner sc=new Scanner(System.in);
 int n = sc.nextInt();
while(n-->0){
int count=0;
String str=sc.next();//nextLine()
for(int i=0;i
if(str.charAt(i)>='0'&&str.charAt(i)<='9'){
count++;
}
}System.out.println(count);
}
  }
}
nextline应该是回车键前的,所以后来运行输入2回车就有了0,next就不会。只是字符。如果需要输空格应该是需要nextline.
0 0