-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment 5
More file actions
32 lines (25 loc) · 927 Bytes
/
Assignment 5
File metadata and controls
32 lines (25 loc) · 927 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
5. code for calculate time duration in which a 340m
long train can pass 160m long tunnel at speed 45 km/hr
package com.google;
public class Ass5 {
public static void main(String[] args) {
int trainLength=340;//340 m long train
double speed=45.0;//45 km/hr speed of train
int tunnel=160; //160m long tunnel
/*
* Here we have given speed in km/hr and length of train and tunnel in m unit...
* first we have to convert km/hr in m/s
* 45 km/hr= 45* 1000/3600 m/s
* Speed= 25/2 m/s
* Total distance to cover (340+160)m= 500m
* time = distance/speed
* 500/ (25/2)
* 500*(2/25)
* 40 seconds
* */
speed=(double) speed*(1000/3600.0);
int distance=tunnel+trainLength;
double time=distance/speed;
System.out.println(" Time required :"+ time+" Seconds");
}
}