Summing - "Enter first floating-point...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.awt.*; import java.util.*; import java.applet.*; import javax.swing.*; i // An applet that requests two double values from the user // and prints their sum public class Summing extends JApplet { private double sum; // the sum of the two values public void init() { String num0; // First number, entered by user String num1; // Second number, entered by user double number0; // First number, as a double double number1; // Second number, as a double // Read in first number num0= JOptionPane.showInputDialog(
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: "Enter first floating-point value"); // Read in second number num1= JOptionPane.showInputDialog( "Enter second floating-point value"); // Convert the two numbers to type double number0= Double.valueOf(num0).doubleValue(); number1= Double.valueOf(num1).doubleValue(); // Add the number sum= number0 + number1; } // Write the results using g public void paint(Graphics g) { g.drawRect(10,10,120,20); g.drawString("The sum is " + sum, 20, 25); } }...
View Full Document

This document was uploaded on 02/24/2010.

Ask a homework question - tutors are online