我收到此错误: - 方法 Format(String, int, int, int) 未定义 类型字符串”
你能帮我解决这个问题吗?我已经尝试了所有其他途径来理解此错误。
Public class Time {
private int hour;
private int minute;
private int second;
public void setTime(int h,int m, int s){
hour = ((h >=0 && h<24)? h:0);
minute = ((m >=0 && m<60)? m:0);
second = ((s >=0 && s<60)? s:0);
}
public String toMilitary() {
return String.Format("%02d:%02d:%02d",hour,minute,second);
}
}
最佳答案
Java区分大小写,你想使用String#format
(以小写f开头):
return String.format("%02d:%02d:%02d",hour,minute,second);
这也适用于Public
,它应该是public
(以小写p开头)。
关于java - 返回字符串格式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23583707/