Skip to content

Commit 0ff1244

Browse files
authored
ElectricVehicleRunningTime.java
1 parent d3be339 commit 0ff1244

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

ElectricVehicleRunningTime.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
public class ElectricVehicleRunningTime {
2+
3+
public static void main(String[] args) {
4+
5+
// Create an array to store the on and off times of the electric vehicle
6+
int[] evTimes = {850, 945, 1145, 1155, 1230, 1245, 1330, 1340, 1425, 1445};
7+
8+
// Calculate the total running time in minutes
9+
int runningTime = 0;
10+
for (int i = 1; i < evTimes.length; i += 2) {
11+
runningTime += evTimes[i] - evTimes[i - 1];
12+
}
13+
14+
// Convert the running time to hours and minutes
15+
int hours = runningTime / 60;
16+
int minutes = runningTime % 60;
17+
18+
// Display the running time
19+
System.out.println("The running time of the electric vehicle is " + hours + " hour(s) and " + minutes + " minute(s).");
20+
}
21+
}

0 commit comments

Comments
 (0)