Beginner Series #4 Cockroach 8 kyu: Codewars Solutions

Beginner Series #4 Cockroach

The cockroach is one of the fastest insects. Write a function which takes its speed in km per hour and returns it in cm per second, rounded down to the integer (= floored).

For example:

1.08 --> 30

Note! The input is a Real number (actual type is language dependent) and is >= 0. The result should be an Integer.

Solution

public class Cockroach{
  public int cockroachSpeed(double x){
        double temp = (x * 100000) / 3600;
        return (int) temp;
  }
}
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments