开发者

Java compiler error - homework assignment

开发者 https://www.devze.com 2023-02-27 05:45 出处:网络
The compiler gives me the error \"\'void\' type not allowed here...<= operator cannot be applied to java.lang.String,int...not a statement\"

The compiler gives me the error "'void' type not allowed here...<= operator cannot be applied to java.lang.String,int...not a statement"

getHours() and getSeconds() return instance variables of type int. Any help would be much appreciated.

 if (userCommand.equals("a")) {
            yourClock.advance();
            System.out.println(yourClock.getSeconds());
            System.out.println("The time is now" +
                    (yourClock.getHours()) <= 9 ? ".0" : ".") +
                    yourClock.getHours() +
                    (yourClock.getMinutes() <= 9 ? ".0" : ".") +
                    yourClock.getMinutes() +
                    (yourClock.getSeconds() <= 9 ? ".0" : ".") +
         开发者_如何学JAVA           yourClock.getSeconds();


You are closing your println in the wrong place. You are closing it after the first getHours() call it should be

if (userCommand.equals("a")) {
            yourClock.advance();
            System.out.println(yourClock.getSeconds());
            System.out.println("The time is now" +
                    (yourClock.getHours() <= 9 ? ".0" : ".") +
                    yourClock.getHours() +
                    (yourClock.getMinutes() <= 9 ? ".0" : ".") +
                    yourClock.getMinutes() +
                    (yourClock.getSeconds() <= 9 ? ".0" : ".") +
                    yourClock.getSeconds());


it looks like you are closing a printout too early

(yourClock.getHours()) <= 9 ? ".0" : ".") +

the closing ) after

getHours())

is closing your printout.


Let's just look at this statement:

(yourClock.getHours()) <= 9 ? ".0" : ".")

Don't you think you are short of a '(' here?

It's better like this:

((yourClock.getHours() <= 9) ? ".0" : ".")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号