如何更正该代码?
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);
.................................................. .............................................. ^
symbol:方法subString(int,int)
location:String类型的变量s
1错误
答案 0 :(得分:1)
您可能应该使用s.substring
查看sub后的小写s
。
答案 1 :(得分:0)
找不到正确写入字符串子字符串的方法。正确的语法是:
input_string.substring(start_position,end_position)