public class Test3 { public static void main(String[] args) { String s1 = "I am"; String s2 = " a student"; String s3; String s4; s3 = s1 + s2; s4 = s3.substring(7, 8); //System.out.println(s3);//连接两个字符串 //System.out.println(s4);//求出第7个字符 //System.out.println(s3.indexOf("am"));//找出“am”在该字符串中的位置 //System.out.println(s3.toUpperCase());//把所有字符都变成大写字符 int a = 0,b = 0,c = 0; for(int i = 0; i < s3.length(); i++){ //48-57代表0-9 if(s3.charAt(i) <= 57 & s3.charAt(i) >= 48){ a++; } //65-90代表A-Z,97-122代表a-z if(s3.charAt(i) <= 90& s3.charAt(i)>=65|s3.charAt(i) <=122&s3.charAt(i) >=97){ b++; } if(s3.charAt(i) == ‘ ‘){ c++; } } System.out.println(a); System.out.println(b); System.out.println(c); } }
时间: 2024-11-05 13:30:40