/** * This class illustrates use of forcing a literal * number to be of a certain type, as well as * showing an example of precision difference * between a float and a double holding the * same value. * * @author Erica Eddy * @version Sept 2009 */ public class Primitives { public static void main (String [] args) { int x = 12; // display x in terminal window System.out.println(x); System.out.print("x = " + x); // make a double representing 1/3 double oneThird = 1/3.0; // display result System.out.println("oneThird = " + oneThird); // make a double representing 2/3 double twoThirds = 2/3.0; // display result System.out.println("twoThirds = " + twoThirds); // print xx's System.out.println("xxx"); // make a float representing 1/3 float oneThirdFloat = 1/3.0F; // display result System.out.println("oneThirdFloat = " + oneThirdFloat); // try expression to see precedence int arith = 7 * 3 - 6 + 2 % 4; // display result System.out.println("arith = " + arith); } }