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.

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.

Convert 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.