public class Ch8_2_2
{
public static void main(String[] args)
{ // 字串物件宣告
String str1="Java is fun";
int i,s=1;
for ( i=0; i < str1.length(); i++)
{
if (str1.charAt(i)!=' ')
{System.out.print(str1.charAt(i));}
else if (str1.charAt(i+1)!=' ')
{s++;
System.out.print(" ");
}
}
String str = new String();
System.out.println(" ");
System.out.println("英文字串長度:"+str1.length());
System.out.println("英文單字個數:"+s);
}
}
全站熱搜
留言列表