// FloatDiv.java
// Demonstrates floating-point division with type float
import javax.swing.JOptionPane; // import class JOptionPane
public class FloatDiv {
public static void main( String[] args )
{
// read in first number from user as a string
String dividendText =
JOptionPane.showInputDialog(
"Enter dividend (floating-point)" );
// read in second number from user as a string
String divisorText =
JOptionPane.showInputDialog(
"Enter divisor (floating-point)" );
// convert numbers from type String to type float
float dividend = Float.parseFloat( dividendText );
float divisor = Float.parseFloat( divisorText );
// divide the numbers
float quotient = dividend / divisor;
// display the results
JOptionPane.showMessageDialog(
null,
dividend + " divided by " + divisor + " is\n" +
quotient + ".",
"Results",
JOptionPane.PLAIN_MESSAGE );
System.exit( 0 ); // terminate the program
} // method main
} // class FloatDiv