简体   繁体   English

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

[英]The method printf(String, Object…) in the type PrintStream is not applicable for the arguments (String, void)

It gives me an error message saying 它给我一个错误信息说

The method printf(String, Object...) in the type PrintStream is not applicable for the arguments (String, void) 类型PrintStream的方法printf(String,Object ...)不适用于参数(String,void)

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());
        }
    }

militaryTime returns void . militaryTime返回void void represents nothing and can't be printed. void代表什么,不能打印。

Perhaps you want militaryTime to return a string representing the military time. 也许您希望militaryTime 返回一个表示军事时间的字符串。 In that case try defining the method as follows: 在这种情况下,请尝试按以下方式定义方法:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PrintStream 类型中的 printf(String, Object[]) 方法不适用于参数 (...) - The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (...) PrintStream 类型中的方法 println(double) 不适用于 arguments (String, double) - The method println(double) in the type PrintStream is not applicable for the arguments (String, double) 声明类型中的方法assertEquals(Object,object)不适用于参数(String,Void) - Method assertEquals(Object, object) in the type Assert is not applicable for the arguments (String, Void) PrintStream 类型中的方法 println(boolean) 不适用于参数 (void) - The method println(boolean) in the type PrintStream is not applicable for the arguments (void) PrintStream 类型中的方法 println(int) 不适用于参数 (String, int, int, int) - The method println(int) in the type PrintStream is not applicable for the arguments (String, int, int, int) ArrayList类型中的方法add(String) <String> 不适用于参数(对象) - The method add(String) in the type ArrayList<String> is not applicable for the arguments (Object) 字符串类型中的方法format(String,Object [])不适用于参数(…) - The method format(String, Object[]) in the type String is not applicable for the arguments (…) OptionTag类型的setValue(String)方法不适用于自变量(对象) - The method setValue(String) in the type OptionTag is not applicable for the arguments (Object) 部分类型中的方法setText(String)不适用于参数 - method setText(String) in the type Part is not applicable for the arguments 类型为nammi的方法epli(String [])不适用于arguments() - The method epli(String[]) in the type nammi is not applicable for the arguments ()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM