为啥我连测试都过不了?

import java.io.PrintStream;
import java.util.Scanner;

public class Maing {

    public static void main(String[] args) throws java.io.UnsupportedEncodingException {
        PrintStream ps = new PrintStream(System.out, true, "UTF-8");
        Scanner in = new Scanner(System.in, "UTF-8");
        String str;
        String result;

        str = in.next();
        switch (str) {
            case "获取某一个位置的字符":
                result = "charAt";
            case "判断字符串内容是否相同":
                result = "equals";
            case "比较大小":
                result = "compareTo";
            case "得到子串":
                result = "substring";
            case "寻找字符":
                result = "indexOf";
            case "判断是否以xxx开始":
            case "全部转成大写":
                result ="toUpperCase";
            case "全部转成小写":
                result = "toLowerCase";
            case "获得长度":
                result = "length";
            default:
                result = "你输入是不是搞错了?";
                break;
        }

        ps.println(result);
    }
}

1 条评论

  • @ 2019-05-17 13:03:14

    代码确实有错。

    1. 你提交之前,在自己的机器上跑测试数据了吗?跑出来结果对吗?
    2. 尝试debug了吗?
  • 1