标签:static col char code += index stat 字符串 string
1 package com.itcast.atd.demo04; 2 3 public class String01 { 4 public static void main(String[] args) { 5 String str="This is a text of java"; 6 int count = 0; 7 8 for (int i = 0; i <str.length() ; i++) { 9 if(str.charAt(i)==‘s‘) 10 count++; 11 } 12 13 System.out.println(count); 14 } 15 }
1 package com.itcast.atd.demo04; 2 3 public class String02 { 4 public static void main(String[] args) { 5 String str="This is a text of java"; 6 int count=0; 7 int index=0; 8 String ctr="is"; 9 10 while((index=str.indexOf(ctr,index))!=-1){ 11 index+=ctr.length(); 12 count++; 13 } 14 15 System.out.println(count); 16 17 } 18 }
package com.itcast.atd.demo04; public class String04 { public static void main(String[] args) { String s="ddejidsEFALDFfnef2357 3ea"; int lcount = 0,ucount = 0,icount = 0; for(int i=0;i<s.length();i++) { char c=s.charAt(i);//返回字符串第i个字符 if(c>=‘a‘&&c<=‘z‘) lcount++; else if(c>=‘A‘&&c<=‘Z‘) ucount++; else icount++; } System.out.println(lcount); System.out.println(ucount); System.out.println(icount); } }
标签:static col char code += index stat 字符串 string
原文地址:https://www.cnblogs.com/changanshisanzhao/p/11601057.html