Write a program to accept the distance travelled by a bus (in Kilometres) and perform the following: - 6 a) Calculate and display the speed(in Km/hr), if the time taken to cover the same distance is 2hours. b) Convert the accepted distance to metres and display it with appropriate message.
Pls Fast
Answers
Answer:
Hindi me likho tabhi to answer de payuga
The user will enter the distance and calculate the speed in km/hr.
Explanation:
import java.util.Scanner;
public class abc
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
float timeSec;
float mps,kph, mph;
System.out.print("Input distance in meters: ");
float distance = scanner.nextFloat();
System.out.print("Input hour: ");
float hr = scanner.nextFloat();
System.out.print("Input minutes: ");
float min = scanner.nextFloat();
System.out.print("Input seconds: ");
float sec = scanner.nextFloat();
timeSec = (hr*3600) + (min*60) + sec;
mps = distance / timeSec;
kph = ( distance/1000.0f ) / ( timeSec/3600.0f );
mph = kph / 1.609f;
System.out.println("Your speed in meters/second is "+mps);
System.out.println("Your speed in km/h is "+kph);
System.out.println("Your speed in miles/h is "+mph);
scanner.close();
}
}