close

題目取自於ITSA協作平台
題目:輸入字串算字元

 

問題描述:

輸入一個字串,然後顯示字元陣列共佔幾個 bytes?

輸入說明:

輸入任一字串。

輸出說明:

會輸出輸入之字串會有幾個字元。

範例:

Sample Input

Sample Output

11+8

Apple

What not?

123456789

There are 4 characters

There are 5 characters

There are 9 characters

There are 9 characters

 

 

Code:

  1. import java.util.Scanner;        
  2. public class Main{        
  3.     public static void main(String[] args){        
  4.         Scanner sc=new Scanner(System.in);              
  5.         int a[]=new int[58];     
  6.         while(sc.hasNext()){  
  7.             String b=sc.nextLine();    
  8.             System.out.println("There are "+b.length()+" characters");  
  9.         }  
  10.     }         
  11. }  
arrow
arrow
    文章標籤
    ITSA JAVA 輸入字串算字元
    全站熱搜

    ニャー提督 發表在 痞客邦 留言(0) 人氣()