代码秃头 2021-04-15 22:06 采纳率: 100%
浏览 19
已采纳

创建time类但是数据传递不进去

package 七周;
import javax.swing.JOptionPane;
public class time {
   private int Hour  ;
   private int Minute ;
   private int Second;
    private void setHour(int newhour) {
        if(newhour >= 0 && newhour <= 24) {
            newhour = this.Hour;
        }
        else
            this.Hour = 0;
    }
    private int getHour() {
        return this.Hour;
    }
    private void setMinute(int newminute) {
        if (newminute >= 0 && newminute <= 60) {
            newminute = this.Minute;
        }
        else
            this.Minute =0;
    }
    private int getMinute() {
        return this.Minute;
    }
    private void setSecond(int newsecond) {
        if (newsecond >= 0 && newsecond <= 60) {
            newsecond = this.Second;
        }
        else 
            this.Second = 0;
    }
    private int getsecond() {
        return this.Second;    
    }
    private String toUniversalString() {
        return this.Hour+":"+this.Minute+":"+this.Second;
    }
    public static void main(String[] args) {
        // TODO 自动生成的方法存根
        time t = new time();
        String output;
        t.setHour(11);
        t.setMinute(45);
        t.setSecond(56);
        output = t.toUniversalString();
        JOptionPane.showMessageDialog(null, output);
    }
}
 

  • 写回答

2条回答 默认 最新

  • 穹龙 2021-04-16 09:25
    关注

    你赋值写反了, this.Hour = newhour;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?