(c) Draw a flowchart and write a program to input the distance travelled in km by a train and time taken by it in hour. Calculate and display the average speed of that train
Answers
Answered by
1
Answer:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the distance travelled by the train in km:");
int distance = sc.nextInt();
System.out.print("Enter the time taken by the train in hours:");
int time = sc.nextInt();
double speed = distance/(double)time;
System.out.println("The average speed of the train is " + speed + " km/h");
}
}
Explanation:
Similar questions