编写Java应用程序,在main方法中定义字符串"How beautiful it was!",统计字母t出现的次数。
来源:百度知道 编辑:UC知道 时间:2024/06/27 05:05:41
public class X65
{
public static void main(String args[])
{
String str="How beautiful it was!";
String st="";
int count=0;
for(int i=0;i<str.length();i++)
{
st=str.substring(i,i+1);
if("t".equals(st))
{
count++;
}
}
System.out.println("出现t的次数为:"+count);
}
}