Dremendo Tag Line

Calculate speed in Java

Input - Question 20

In this question, we will see how to input distance in kilometer, time in minutes in Java programming using the java input and find the speed. To know more about java input click on the java input lesson.

Q20) Write a program in Java to input distance in kilometer, time in minutes and find the speed.

Formula: Speed = Distance / Time


import java.util.Scanner;

public class Q20
    public static void main(String args[])
        int d,t;
        float s;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter distance in km ");
        System.out.print("Enter time in minutes ");
        System.out.print("Speed = " + s + " km per minute");


Enter distance in km 70
Enter time in minutes 50
Speed = 1.4 km per minute