Computer Science, asked by shivangisharma53799, 3 months ago

write a program that reads the value of distance travelled by a car and the time taken for the same.next compute the speed at which the car is travelled​

Answers

Answered by BrainlyProgrammer
19

//Java program to accept distance and time from user and display speed of the car

package programmer;

import java.util.*;

public class Distance

{

public static void main (String ar [])

{

Scanner sc=new Scanner (System.in);

double distance,speed; //Declaration of the variable

int time;

System.out.println("Enter distance in metre and time in second");

distance=sc.nextDouble();

time=sc.nextInt(); //Accepting input from the user

speed=distance/time; //Calculating speed

System.out.println("Speed of the car:"+speed+"m/s");

}

}

Variable Description:-

  • distance:- to accept distance of the car from the user as input
  • time:- to accept time taken by the car as input
  • speed :- to Calculate speed of the car

•Output attached

Attachments:
Similar questions