Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DataTypeAndVariables;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.text.DecimalFormat;
- public class P11_ConvertSpeedUnits {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- DecimalFormat first = new DecimalFormat("#.#######");
- DecimalFormat second = new DecimalFormat("#.######");
- DecimalFormat third = new DecimalFormat("##.#####");
- DecimalFormat fourth = new DecimalFormat("###.####");
- int distanceMeter = Integer.parseInt(reader.readLine());
- int hours = Integer.parseInt(reader.readLine());
- int minutes = Integer.parseInt(reader.readLine());
- int seconds = Integer.parseInt(reader.readLine());
- int allMinutes = (hours * 60) + minutes;
- int allSeconds = (allMinutes * 60) + seconds;
- int allTime = hours * 3600 + minutes * 60 + seconds;
- float allHours = allSeconds * 0.000277777778f;
- float allKm = distanceMeter * 0.001f;
- float meterPerSeconds = (float)distanceMeter / allSeconds;
- float kmPerHour = allKm / allHours;
- float milePerHour = (distanceMeter / (float)1609) / (allTime / (float)3600);
- if (meterPerSeconds > 0 && meterPerSeconds < 1) {
- System.out.println(first.format(meterPerSeconds));
- }
- if (kmPerHour > 0 && kmPerHour < 1) {
- System.out.println(first.format(kmPerHour));
- }
- if (milePerHour > 0 && milePerHour < 1) {
- System.out.println(first.format(milePerHour));
- }
- if (meterPerSeconds > 0 && meterPerSeconds < 10) {
- System.out.println(second.format(meterPerSeconds));
- }
- if (kmPerHour > 0 && kmPerHour < 10) {
- System.out.println(second.format(kmPerHour));
- }
- if (milePerHour > 0 && milePerHour < 10) {
- System.out.println(second.format(milePerHour));
- }
- if (meterPerSeconds > 9 && meterPerSeconds < 100) {
- System.out.println(third.format(meterPerSeconds));
- }
- if (kmPerHour > 9 && kmPerHour < 100) {
- System.out.println(third.format(kmPerHour));
- }
- if (milePerHour > 9 && milePerHour < 100) {
- System.out.println(third.format(milePerHour));
- }
- if (meterPerSeconds > 99) {
- System.out.println(fourth.format(meterPerSeconds));
- }
- if (kmPerHour > 99) {
- System.out.println(fourth.format(kmPerHour));
- }
- if (milePerHour > 99) {
- System.out.println(fourth.format(milePerHour));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement