Tuesday, 26 July 2016

Write a program which will take time(hour) and distance(km) as parameters and print the speed in kmph.

Write a program which will take time(hour) and distance(km) as parameters and print the speed in  kmph.
Input Specification :
First input is a value of time in hour.
Second input is a value of distance in km.
Output Specification:
Calculate the value of speed up to two decimal places.
Sample Input:
3
65
Sample Output:
21.67
Note: Print the output upto 2 decimal places

import java.util.*;
class Speed{
    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        float h=s.nextInt();
        float k=s.nextInt();
        //long kh=k/h;
        //System.out.println(kh);
        System.out.format("%.2f%n", k/h);
    }
}

No comments: