English 中文(简体)
如果还有 Java 试图阻止声明的表状,
原标题:If and else statments Java trying to stop a statement Homework

这是我的密码...

private void updateDisplay() {
    if(hours.getValue() == 0){
        hours.setValue(12);
        displayString = hours.getDisplayValue() + ":" + 
        minutes.getDisplayValue() + " am"; 
    }
    else if(hours.getValue() < 12){
        displayString = hours.getDisplayValue() + ":" + 
        minutes.getDisplayValue() + " am";
    }
    else if(hours.getValue() == 12){
        displayString = hours.getDisplayValue() + ":" + 
        minutes.getDisplayValue() + " pm";
    }
    else if(hours.getValue() < 24){ 
        displayString = hours.getValue() - 12 + ":" +  
        minutes.getDisplayValue() + " pm"; 
    }
}

基本上,这是一个试图以 12 小时格式显示的时钟。 当它从 11: 59 时改变 。

我得到它说12: 00,但一旦我时间Tick () 一旦它到达12: 01 下午, 因为我的时数。getValue = = 0 然后我们把它变成12,但是在方法的后期 如果时间。getValue () = 12 make it PM。我想避免这一点。在保持相当简单的 Java的同时,有什么想法吗?

谢谢,我不再设置Value( 12), 我刚刚加了12小时。 getValue () = 0

最佳回答

为什么不只是做你做什么 当时间等于12?

不要实际设定时数值,只要在打印时加12。

问题回答

使用内部24小时时, 但使用“ 小时模式 12 ” 显示其值 。

假设 hours. getValue () returns a hours. getValue ()/13 = = 0 = 0 = 0 = = 0? hours. getValue ()+ ":" + minute + " AM" : hours.get Value () - 12 + ":"+ minutes. get display value ()+ "PM"; 。 表达式称为“ 长期操作器” 和“ int数据类型” 三进制结果 。

我更新了它,可以做任何事 希望你喜欢一行内衣





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签