Computer Science, asked by ahaangandhi1425, 11 months ago

Write an algorithm that accept the distance and speed values for a particular journey calculate the time taken by the journey and display it

Answers

Answered by OjasNaik
1
here is the java program for it

class hsjdb
{
public void main(double d, double s)
{
double t;
t=d/s;
System.out.println(t);
}}
Answered by ravilaccs
0

Answer:

A set of well-defined instructions for solving a certain issue is known as an algorithm. It accepts a collection of inputs and outputs the desired result.

Explanation:

Method1:

Step1: Start the algorithm.

Step 2:  Enter the distance in kilometers.

Step 3: Meters=distance in kilometers*1000

Step 4: Display the Meters.

Step 5: End the algorithm.

Program:

import java.util.Scanner;

public class Exercise7 {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

float timeSeconds;

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();

timeSeconds = (hr*3600) + (min*60) + sec;

mps = distance / timeSeconds;

kph = ( distance/1000.0f ) / ( timeSeconds/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();

}

}

Similar questions