//ConversionDemo.java //Demonstrates primitive typecasting //Andy Harris, 05/00 import java.awt.*; import java.applet.*; import java.awt.event.*; public class ConversionDemo extends Applet implements ActionListener { public void init(){ //The next line will cause an error!! //I commented it out so the program will run //int answer1 = 54.8 + 21.7; System.out.println("54.8 + 21.7 = " + (54.8 + 21.7)); //The next line will be OK int answer2 = (int)(54.8 + 21.7); System.out.println("answer2 is " + answer2); //of course, some detail will have been lost //This is different than int answer3 = (int)54.8 + (int)21.7; System.out.println("(int)54.8 = " + (int)54.8); System.out.println("(int)21.7 = " + (int)21.7); System.out.println("answer3 is " + answer3); } // end init public void actionPerformed(ActionEvent e){ //do nothing } // end action } // end class def