package cn.ly.Day.seven.fifteen;
public class Demo05StringPractise {
public static void main(String[] args) {
int[] array={1,2,3};
String result=fromArrayToString(array);
System.out.println(result);
}
public static String fromArrayToString(int[] array){
String str="[";
for (int i = 0; i < array.length; i++) {
if(i==array.length-1){
str+="word"+array[i]+"]";
}else{
str+="word"+array[i]+"#";
}
}
return str;
}
}
package cn.ly.Day.seven.fifteen;
import java.util.Scanner;
public class Demo06StringCount {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入一个字符串");
String str=sc.next();
int countUpper=0;
int countLower=0;
int counNumber=0;
int countOther=0;
char[] charArray=str.toCharArray();
for (int i = 0; i < charArray.length; i++) {
char ch=charArray[i];
if('A'<=ch&&ch<='Z'){
countUpper++;
}else if('a'<=ch&&ch<='z'){
countLower++;
}else if('0'<=ch&&ch<='9'){
counNumber++;
}else {
countOther++;
}
}
System.out.println("大写字母个数:"+countUpper);
System.out.println("小写字母个数:"+countLower);
System.out.println("数字的个数:"+counNumber);
System.out.println("其他字符的个数:"+countOther);
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9a5e64166c8a53e98c491509d6d558c9.png)