十月十九日作业

第一题:

package com.hp.www;

public class Demo2 {
    public static void main(String[] args) {
        String s = "Hello-World";
        System.out.println("是否相等,-"+s.equals("World"));
        System.out.println("Wo起始索引:"+s.indexOf("Wo"));
        System.out.println("3好索引"+s.charAt(3));
        System.out.println("长度"+s.length());
        System.out.println("获得s中的Hell字符串:"+s.valueOf("Hell"));
        System.out.println("获得s中的orld字符串:"+s.valueOf("orld"));
        System.out.println("将字符串s中的所有o替换成*号."+s.replace("o","*"));
        System.out.println("将字符串s切割Hell和World两个字符串."+s.replace(s,"Hello"));
        char []chars = s.toCharArray();
        for(char a:chars

        ){
            System.out.print(a+",");
        }
    }
}

第二题:

package com.hp.www;

import java.util.Scanner;

public class Demo3 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        String s= scanner.next();
        char[] c=s.toCharArray();
        int smallCount=0;
        int bigCount=0;
        int numCount=0;
        for (int i = 0; i <s.length() ; i++) {
            if (Character.isUpperCase(c[i])) {
                bigCount++;
            }
            else if (Character.isLowerCase(c[i])) {
                smallCount++;
            }else if (Character.isDigit(c[i])) {
                numCount++;
            }
        }
        System.out.println("大写字母数量为:"+bigCount);
        System.out.println("小写字母数量为:"+smallCount);
        System.out.println("数字数量为:"+numCount);
    }
}

第三题:

package com.hp.www;

import java.util.Scanner;

public class Demo4 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("键盘录入5个字符串");
        String[]arr=new String[5];
        for (int i = 0; i <5 ; i++) {
            String s= scanner.next();
            arr[i]=s;
        }
        int smallCount=0;
        int bigCount=0;
        int numCoun=0;
        for (int i = 0; i <arr.length ; i++) {
            char[]c =arr[i].toCharArray();
            for (int j = 0; j <c.length ; j++) {
                if(Character.isLowerCase(c[i])){
                    bigCount++;
                }
                else if (Character.isLowerCase(c[i])){
                    smallCount++;
                }else if(Character.isDigit(c[i])){
                    numCoun++;
                }
            }
        }
        System.out.println("大写字母数量为:"+bigCount);
        System.out.println("小写字母数量为:"+smallCount);
        System.out.println("数字数量为:"+numCoun);
    }
}

 

posted on 2020-10-19 20:59  Cxgg0  阅读(59)  评论(0编辑  收藏  举报