Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {

    public static String addUnit(float distance) {
        if (distance == 0) {
            return "0M";
        } else {
            if (distance > 1000) {
                distance = distance / 1000;
                distance = (float) ((double) Math.round(distance * 100) / 100);
                return distance + "KM";
            } else {
                distance = (float) ((double) Math.round(distance * 100) / 100);
                return distance + "M";
            }
        }
    }
}