NexeInt()、nextLine()、

xiaoxiao2021-02-28  44

1.先输入数字n,表示要统计的行数

2.输入n行字串,回车结束,进行统计其中的汉字的个数

public class Next { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); while(n-->0){ String str = sc.nextLine(); char chs[] = str.toCharArray(); int count=0; for(int i=0;i<chs.length;i++){ if(chs[i]>127){ count++; } } System.out.println(count); } } }

输出的结果如下:

转载请注明原文地址: https://www.6miu.com/read-2624029.html

最新回复(0)