FileDocCategorySizeDatePackage
CastingDemo.javaAPI DocExample425Sat Nov 25 12:55:38 GMT 2000None

CastingDemo

public class CastingDemo extends Object
A simple casting demo.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)

		int i, ans;
		double d = 2.75;
		i = d;			// EXPECT COMPILE ERROR
		i = (int)d;		// with cast; i gets 2
		System.out.println("i =" + i);
		ans = (int)d * 3;		// truncate d before multiplying
		System.out.println("ans =" + ans);
		ans = (int)(d * 3);	// multiplies before truncating
		System.out.println("ans =" + ans);