String 类型

第一题

package step1;
import java.util.Scanner;

public class EasyString {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String str = input.nextLine();
        input.close();

        char head = ' ';
        char end = ' ';
        int length = 0;

        //请在指定位置填写代码。
        /********* Begin *********/
length=str.length();
head=str.charAt(0);
end=str.charAt(str.length()-1);
        /********* End *********/

        System.out.print(String.format("%d %c %c", length, head, end));
    }
}

第二题

package step2;
import java.util.Scanner;

public class SSN {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        String ssn = input.nextLine();
        input.close();
        String output = "";

        //请在指定位置填写代码。
        /********* Begin *********/
        output = "yes";
        if(Character.isDigit(ssn.charAt(0))){
            output = "yes";
        }
        else{
            System.out.print(output="no");
            System.exit(0);
        }
        if(Character.isDigit(ssn.charAt(1))){
            output = "yes";
        }
        else{
            System.out.print(output="no");
            System.exit(0);
        }
        if(Character.isDigit(ssn.charAt(2))){
            output = "yes";
        }
        else{
            System.out.print(output="no");
            System.exit(0);
        }
        if('-' == ssn.charAt(3)){
            output = "yes";
        }
        else{
            System.out.print(output="no");
            System.exit(0);
        }
        if(Character.isDigit(ssn.charAt(4))){
            output = "yes";
        }
        else{
            System.out.print(output="no");
            System.exit(0);
        }
        if(Character.isDigit(ssn.charAt(5))){
            output = "yes";
        }
        else{
            System.out.print(output="no");
            System.exit(0);
        }
        if('-' == ssn.charAt(6)){
            output = "yes";
        }
        else{
            System.out.print(output="no");
            System.exit(0);
        }
        if(Character.isDigit(ssn.charAt(7))){
            output = "yes";
        }
        else{
            System.out.print(output="no");
            System.exit(0);
        }
        if(Character.isDigit(ssn.charAt(8))){
            output = "yes";
        }
        else{
            System.out.print(output="no");
            System.exit(0);
        }
        if(Character.isDigit(ssn.charAt(9))){
            output = "yes";
        }
        else{
            System.out.print(output="no");
            System.exit(0);
        }
        if(Character.isDigit(ssn.charAt(10))){
            output = "yes";
        }
        else{
            System.out.print(output="no");
            System.exit(0);
        }
        if(Character.isDigit(ssn.charAt(11))){
            output = "yes";
        }
        else{
            System.out.print(output="no");
            System.exit(0);
        }
        if(ssn.length() != 12){
            output = "no";
        }



        /********* End *********/

        System.out.print(output);
    }
}

第三题

package step3;
import java.util.Scanner;

public class SubString {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String name  = input.nextLine();
        input.close();

        //请在指定位置填写代码。
        /********* Begin *********/
     
        if(name.contains("*")){
            System.out.println(name.replaceAll(" ","").substring(0,2));
            System.out.print(name.replaceAll(" ","").substring(2,name.replaceAll(" ","").length()-1));
        }
        else{
            System.out.println(name.replaceAll(" ","").substring(0,1));
            System.out.print(name.replaceAll(" ","").substring(1,name.replaceAll(" ","").length()));
        }

        /********* End *********/
    }
}

第四题
CEHI

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值