题解 | #统计字符#
统计字符
https://www.nowcoder.com/practice/539054b4c33b4776bc350155f7abd8f5
import java.util.*; public class Main { public static void main(String[] args) { Scanner fzhinput = new Scanner((System.in)); String zfc = fzhinput.nextLine(); int zmnum=0,spacenum=0,nnum=0,qtnum=0; for(int i=0;i<zfc.length();i++){ char c = zfc.charAt(i); if(Character.isLetter(c)){ zmnum++; } else if(c ==' '){ spacenum++; } else if(Character.isDigit(c)){ nnum++; } else{ qtnum++; } } System.out.println(zmnum); System.out.println(spacenum); System.out.println(nnum); System.out.println(qtnum); } }