-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ4.java
More file actions
49 lines (48 loc) · 1.13 KB
/
Q4.java
File metadata and controls
49 lines (48 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.*;
import java.io.*;
class Time {
int hr,min,sec;
Time(int h,int m,int s){
hr=h;
min=m;
sec=s;
}
Time add(Time t1,Time t2){
Time t3 = new Time(0, 0, 0);
t3.sec=t1.sec+t2.sec;
t3.min=t1.min+t2.min;
t3.hr=t1.hr+t2.hr;
if (t3.sec>=60){
t3.sec=00;
t3.min++;
}
if (t3.min>=60){
t3.min=00;
t3.hr++;
}
return t3;
}
void display(){
System.out.print("Total Time: " + hr + ":" + min + ":" + sec);
}
};
public class Q4 {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("enter time t1 := ");
int h1,m1,s1;
h1=sc.nextInt();
m1=sc.nextInt();
s1=sc.nextInt();
Time t1=new Time(h1,m1,s1);
System.out.println("enter time t2 := ");
int h2,m2,s2;
h2=sc.nextInt();
m2=sc.nextInt();
s2=sc.nextInt();
Time t2=new Time(h2,m2,s2);
Time t3=new Time(0, 0, 0);
t3=t3.add(t1, t2);
t3.display();
}
}