回覆列表
  • 1 # pzyyo24296

    不用那麼複雜,漢字倆位元組,英文一個位元組,計算下關係就可以了public class Test { public static void main(String[] args) { Scanner s = new Scanner(System.in, "GBK"); String input = s.nextLine(); byte[] inputBytes = input.getBytes(); System.out.println("英文字元數:" + (2* input.length() - inputBytes.length)); System.out.println("漢字字元數:" + (inputBytes.length - input.length()) ); }}

  • 2 # 使用者5083044991728

    System.out.println("請輸入字串:"); Scanner s = new Scanner(System.in); String string = s.nextLine(); System.out.println(string); int x=0,y=0,c=0,b=0,sum=string.length(); for (int i=0;i<=sum-1;i++){ if (string.codePointAt(i)>=48 && string.codePointAt(i)<=57){ x++; } else if(string.codePointAt(i)>=65&&string.codePointAt(i)<=90||string.codePointAt(i)>=97&&string.codePointAt(i)<=122){ y++; } else if (string.codePointAt(i)==32) { c++; } else { b++; } } System.out.println("總共有"+sum+"個字元!"+"數字有"+x+"個,"+"字母有"+y+"個,"+"空格有"+c+"個,"+"其他字元有"+b+"個。");

  • 中秋節和大豐收的關聯?
  • 泰倫盧明確表示騎士將進入重建,你認為騎士隊重建的核心會有哪些球員?為什麼?