提问者:小点点

PrintStream类型中的printf(String, Object...)方法不适用于参数(String, val)


它给我一条错误消息,说

PrintStream类型中的printf(String, Object...)方法不适用于参数(String, val)

public class project {

        public static void main(String[] args){

        duo duoObject = new duo();
        duo duoObject1 = new duo(5);
        duo duoObject2 = new duo(2,6);
        duo duoObject3 = new duo(3,7,5);
        System.out.printf("%s\n", duoObject.militaryTime());
        System.out.printf("%s\n", duoObject1.militaryTime());
        System.out.printf("%s\n", duoObject2.militaryTime());
        System.out.printf("%s\n", duoObject3.militaryTime());
        }

    }


    public class duo {
        private int hour;
        private int minute;
        private int second;

        public duo(){

        }
        public duo(int h){
            setHour(h);
        }
        public duo(int h, int m){
            setHour(h);
            setHour(m);
        }
        public duo(int h, int m, int s){
            setHour(h);
            setHour(m);
            setHour(s);
        }
        public void setHour(int h){
            hour = ((h>=0 && h<24)? h : 0);
        }
        public void setMinute(int h){
            minute = ((h>=0 && h<60)? h : 0);
        }
        public void setSecond(int h){
            second = ((h>=0 && h<60)? h : 0);
        }
        public int getHour(){
            return hour;
        }
        public int getMinute(){
            return minute;
        }
        public int getSecond(){
            return second;
        }
        public void militaryTime(){
            System.out.printf("%02d:%02d:%02d", getHour(), getMinute(), getSecond());
        }
    }

共1个答案

匿名用户

军事时间返回无用无用不代表任何内容,无法打印。

也许您希望军事时间返回一个表示军事时间的字符串。在这种情况下,请尝试将方法定义如下:

public String militaryTime() {
    return String.format("%02d:%02d:%02d", getHour(), getMinute(), getSecond());
}