Using Real Numbers
In this example the conversion of inches to centimeters requires a result with a decimal place. To allow this the variable holding the centimeters is declared as a double.
import java.awt.*;
import java.applet.Applet;
public class Converter extends Applet
{int inches;
double centimeters;
public void init()
{inches = 12;
centimeters = inches * 2.54;}
public void paint(Graphics g)
{g.drawString(inches + " inches = " + centimeters + " centimeters", 50, 50);
}
}