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);
}
}
创建time类但是数据传递不进去
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
穹龙 2021-04-16 09:25关注你赋值写反了, this.Hour = newhour;
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报