Java基础篇--工具类操作之设定一个有大小写字母的字符串,先将字符串的大写字符输出,再将字符串中的小写字符输出。

编写一个程序,设定一个有大小写字母的字符串,先将字符串的大写字符输出,再将字符串中的小写字符输出。

实现方法不唯一,此方法仅作初学者(自己)参考。。。。。

所用类API介绍:
Java基础篇--工具类操作之设定一个有大小写字母的字符串,先将字符串的大写字符输出,再将字符串中的小写字符输出。

所用方法介绍:
Java基础篇--工具类操作之设定一个有大小写字母的字符串,先将字符串的大写字符输出,再将字符串中的小写字符输出。
Java基础篇--工具类操作之设定一个有大小写字母的字符串,先将字符串的大写字符输出,再将字符串中的小写字符输出。

Java基础篇--工具类操作之设定一个有大小写字母的字符串,先将字符串的大写字符输出,再将字符串中的小写字符输出。

实现代码:

package com.string;

import java.util.Scanner;
import java.util.SplittableRandom;

public class Print_Stirng {
    public static void main(String[] args) {
        System.out.println("请输入字符串:");
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        char[] s = str.toCharArray();
        System.out.print("小写字母: ");
        for (char s1:s) {
            if(Character.isLowerCase(s1))
            System.out.print(s1+" ");
        }
        System.out.println();
        System.out.print("大写字母:");
        for (char s2:s) {
            if (Character.isUpperCase(s2))
                System.out.print(s2+" ");
        }
        System.out.println();
        System.out.print("数字:");
        for (char s3:s) {
            if (Character.isDigit(s3))
                System.out.print(s3+" ");

        }

    }
}

实现结果:
Java基础篇--工具类操作之设定一个有大小写字母的字符串,先将字符串的大写字符输出,再将字符串中的小写字符输出。