杭电oj —— 2017

import java.util.Scanner;

public class HDU_oj2017 {
	/*
	 * 对于给定的一个字符串,统计其中数字字符出现的次数
	 * InputMisMatchException  输入类型不匹配
	 */
	public static void main(String[] args) {
		Scanner sn = new Scanner(System.in);
		while (sn.hasNext()) {
			int n = sn.nextInt();
			String[] str = new String[n];
		    int[] count  = new int[n];
			for (int i = 0; i < n; i++) {
				//用nextLine就必须后面全都用nextLine,nextLine不要和next  nextInt一起用
				str[i] = sn.next();
				
				for(int j = 0; j<str[i].length();j++) {
					//java自带的 判断是否为数字
					if(Character.isDigit(str[i].charAt(j))){
						count[i]++;
					}
				}
			}
			
			for(int i = 0;i < n;i++) {
				System.out.println(count[i]);
			}

		}

	}

}

详情Java中判断字符串是否为数字的五种方法

请见:https://www.cnblogs.com/heyuxiu/p/5972187.html

猜你喜欢

转载自blog.csdn.net/LiLi_code/article/details/87649070