【问题标题】:Java cannot find the the String in method [closed]Java在方法中找不到字符串[关闭]
【发布时间】:2018-03-27 05:21:32
【问题描述】:

如何更正该代码?

public class Solution {

    static String timeConversion(String s) {
        String sub=s.subString(0,2);         
        System.out.println(sub);
        return "test";
    }
    private static final Scanner scan = new  Scanner(System.in);

    public static void main(String[] args) throws IOException {
        BufferedWriter bw
                   = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
        String s = scan.nextLine();
        String result = timeConversion(s);
        bw.write(result);
        bw.newLine();
        bw.close();
    }
}

Solution.java:12:错误:找不到符号 String sub=s.subString(0,2);
..................................................... ....................................^

符号:方法 subString(int,int)

位置:String类型的变量s

1 个错误

【问题讨论】:

  • s.substring(0,2);
  • 在 sunstring 中是小写 s 使用子字符串而不是子字符串

标签: java string static-methods


【解决方案1】:

也许你应该使用s.substring,在sub之后看到小写的s

【讨论】:

    【解决方案2】:

    查找字符串子串的方法写的不正确。正确的语法是:

    input_string.substring(start_position, end_position)

    【讨论】:

      猜你喜欢
      • 2012-04-26
      • 2011-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 2014-01-18
      相关资源
      最近更新 更多