FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 70   



Following program shows you how to convert grams to kilograms.
In this program we get grams from user, once we get those we need to divide with 1000 so that we get in kilograms

import java.util.Scanner;

public class MathUnitConversions8 {

    public static void main(String[] args) {

        double grams;

        Scanner in = new Scanner(System.in);

        System.out.println("Please enter grams:");
        grams = in.nextDouble();

        double kilograms = grams / 1000;
        System.out.println(kilograms + " Kilograms");

    }
}

Output:

Please enter grams:
30
0.03 Kilograms



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News