Programming Exercise - PowerPoint PPT Presentation

1 / 4
About This Presentation
Title:

Programming Exercise

Description:

Programming Exercise. Flow chart. Result. product of the two. Numeric. Second integer ... If variable A entered by user is numeric ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 5
Provided by: pcbstud
Category:

less

Transcript and Presenter's Notes

Title: Programming Exercise


1
Programming Exercise
  • Flow chart

First integer
Multiply first integer by second integer
Second integer
Numeric
Result product of the two
2
  • PsuedoCode
  • If variable A entered by user is numeric
  • Display the button where user can enter the
    second number
  • Else display message Try again
  • If variable B is numeric
  • Multiply variable A by B
  • Calculate the sum of A B
  • Else display message Try again

3
  • // program Multiply.java
  • // An addition program
  • import javax.swing.JOptionPane // import
    class JOptionPane
  • public class Multiply
  • public static void main( String args )
  • String firstNumber, // first string
    entered by user
  • secondNumber // second string
    entered by user
  • int number1, // first number to
    add
  • number2, // second number to
    add
  • product // product of
    number1 and number2
  • // read in first number from user as a
    string
  • firstNumber
  • JOptionPane.showInputDialog( "Enter
    first integer" )

4
  • // read in second number from user as a string
  • secondNumber
  • JOptionPane.showInputDialog( "Enter
    second integer" )
  • // convert numbers from type String to type
    int
  • number1 Integer.parseInt( firstNumber
    )
  • number2 Integer.parseInt( secondNumber
    )
  • // multiply the numbers
  • product number1 number2
  • // display the results
  • JOptionPane.showMessageDialog(
  • null, "The sum is " sum, "Results",
  • JOptionPane.PLAIN_MESSAGE )
  • System.exit( 0 ) // terminate the
    program
Write a Comment
User Comments (0)
About PowerShow.com