Home Java Java-conversion Convert Grams To Ounce



Convert Grams To Ounce
Posted on: February 27, 2008 at 12:00 AM
In this section, you will learn to convert Grams To Ounce. The following program helps you in converting Grams To Ounce.

Convert Grams To Ounce

     

In this section, you will learn to convert Grams To Ounce. The following program helps you in converting Grams To Ounce. 

Code Description:

To convert Grams To Ounce we have used a formula "ounce = gram * 0.035273962;". The compiler will ask to enter the number of Grams from the keyboard due to the method  "
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));". Here we have taken Grams to be of type Int. To avoid loss of precession we have cast the output to be in double.

Here is the code of the program:

import java.io.*;
import java.util.*;

class GmsToOunce {
  public static void main(String[] argsthrows Exception{
  //1 gram = 0.035 273 962 ounce
  BufferedReader bf = new BufferedReader(new 
  InputStreamReader
(System.in));
  System.out.println("Enter the Grams:");
  int Grams = Integer.parseInt(bf.readLine());
  double Ounce = Grams * 0.035273962;  
  System.out.println("Ounce:" + Ounce);
  }
}

Output of the program:

C:\unique>javac GmsToOunce.java

C:\unique>java GmsToOunce
Enter the Grams:
2
Ounce:0.070547924

C:\unique>

Download this example.

Related Tags for Convert Grams To Ounce:
cconvertiohelpthisuncprogramtolearnrameareilsectionceinconvertingmpsprosisllfolloweaarrtwingssthpronogrolo


More Tutorials from this section

Ask Questions?    Discuss: Convert Grams To Ounce  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.