Created
October 2, 2017 13:58
-
-
Save PocasPedro/3753a9e2aecba6ae4cb063f54fbbc944 to your computer and use it in GitHub Desktop.
Java Fundaments for Kids - Exercise 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Program that calculates the Average Speed of a Car | |
I made the program to calculate only the speed that was asked for the exercise. Could have made it to ask the user to introduce its own values but I think thats more complex | |
than what was aked | |
*/ | |
public class CarSpeed { | |
public static void main(String[] args) { | |
int distance = 100; //distance in meters | |
int time = 5; //time in seconds | |
float average = ( (distance/1000) / (time/3600) ); /*distance is by convention given in km/hour. since our variables are in meters and seconds, we have to divide the distance | |
by 1000 because 1km = 1000 meters and divide the time by 3600 because 1h = 3600 seconds;*/ | |
// Prints the Average Speed in the terminal | |
System.out.println("The average speed of our car is " + average + " km/h!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment