-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecondMinute.java
More file actions
38 lines (33 loc) · 913 Bytes
/
SecondMinute.java
File metadata and controls
38 lines (33 loc) · 913 Bytes
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
package part;
public class SecondMinute {
private static final String INVALID_VALUE_MESSAGE = "Invalid value";
public static void main(String[] args) {
System.out.println(getDurationString(61, 0));
System.out.println(getDurationString(65, 45));
System.out.println(getDurationString(3945));
}
public static String getDurationString(int minutes, int seconds) {
if(minutes >= 0) {
if(seconds >= 0 && seconds <= 59) {
int hours = 0;
if(minutes >= 60) {
hours = minutes / 60;
minutes = minutes % 60;
}
return hours + "h " + minutes + "m " + seconds + "s ";
}
}
return INVALID_VALUE_MESSAGE;
}
public static String getDurationString(int seconds) {
if(seconds >= 0) {
int minutes = 0;
if(seconds >= 60) {
minutes = seconds / 60;
seconds = seconds % 60;
}
return getDurationString(minutes, seconds);
}
return INVALID_VALUE_MESSAGE;
}
}