JAVA 中 构造方法和成员方法的具体定义,在程序中分别代表什么作用。
发布网友
发布时间:2022-04-24 17:45
我来回答
共1个回答
热心网友
时间:2023-10-27 23:17
public
class
time
{
private
int
hr;
private
int
min;
private
int
sec;
public
void
time()
{
hr
=
0;
min
=
0;
sec
=
0;
}
public
void
showtime(int
h,int
m,int
s)
{
system.out.println(hr+":"+min+":"+sec);
}
public
void
addtime(int
h,int
m,int
s)
{
int
temp_m,temp_h;
int
nhr,nmin,nsec
if((s
+
sec)
>=
60)
{
temp_m
=
min;
min++;
nsec
=
sec
+
s
-
60;
}
else
{
nsec
=
sec
+
s;
}
if((min
+
m)
>=
60)
{
temp_h
=
hr;
hr++;
nmin
=
min
+
m
-
60;
}
else
{
nmin
=
min
+
m;
}
if((hr
+
h)
>
24)
{
nhr
=
hr
+
h
-
24;
}
else
{
nhr
=
hr
+
h;
}
hr
=
temp_h;
min
=
temp_m;
showtime(nhr,nmin,nsec);
}
public
void
difftime(int
h,int
m,int
s)
{
int
temp_m,temp_h;
int
nhr;
int
nmin;
int
nsec;
if(sec
<
s)
{
temp_m
=
min;
nsec
=
sec
+
60
-
s;
min--;
}
else
{
nsec
=
sec
-
s;
}
if(min
<
m)
{
temp_h
=
hr;
nmin
=
min
+
60
-
s;
hr--;
}
else
{
nmin
=
min
-
m;
}
nhr
=
hr
-
h;
hr
=
temp_h;
min
=
temp_m;
showtime(nhr,nmin,nsec);
}
}
急急忙忙写的,没有测试过,你自己试试看,不行就再调试一下。