题解 | #统计大写字母个数#
统计大写字母个数
https://www.nowcoder.com/practice/434414efe5ea48e5b06ebf2b35434a9c
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.*; import java.util.stream.IntStream; import java.util.stream.Stream; import static java.util.Arrays.*; import static java.util.stream.Stream.*; public class Main { public static void main(String[] args) throws IOException { //testCompletePack(); testTh(); } private static void testTh() throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String str; while ((str = bf.readLine()) != null) { String reg = "[A-Z]"; int count = 0; char[] chars = str.toCharArray(); for (char aChar : chars) { String s = aChar + ""; boolean matches = s.matches(reg); if (matches) { count++; } } System.out.println(count); } } }