Results 1 to 4 of 4
  1. #1
    mandalay92 is offline Member
    Join Date
    Aug 2008
    Posts
    2
    Rep Power
    0

    Default Can't Remember How to Do This

    In programming class, we just learned some very simple java. However, now I can't remember the code! Can someone tell me what I'm doing wrong?
    import javax.swing.JOptionPane;


    public class InputOutput {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    System.out.println("Hello World!");//Output
    int num1;
    int num2;
    int sum;
    string input1;
    string input2;

    System.out.println("Enter an integer.");
    input1=JOptionPane.showInputDialog("Input an integer...");
    input2=JOptionPane.showInputDialog("Input another.");
    num1=Int.parseInt(input1);
    num2=Int.parseInt(input2);
    sum=num1+num2;
    System.out.println("The sum is"sum);

    }

    }

  2. #2
    ruuebs is offline Member
    Join Date
    Aug 2008
    Posts
    4
    Rep Power
    0

    Default

    You need to fix the following:

    - Add the code
    Java Code:
    Import javax.swing*;
    to the top of the class because you're using JOptionPane from the Swing libarary.

    - The String Class is always spelt with a capital S, like all class names.

    -
    Java Code:
    [B]Integer[/B].parseInt(input1);
    Not
    Java Code:
    Int.parseInt(input1);
    (int is a prmitive data type while Integer is an Object wrapper class)

    -and lastly you need to use the + sign to add something to a String like:
    Java Code:
    System.out.println("The sum is " [B]+[/B] sum);
    Hope that helps.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default

    If you are getting errors, please copy and post the full text of the error message here.

  4. #4
    mandalay92 is offline Member
    Join Date
    Aug 2008
    Posts
    2
    Rep Power
    0

Similar Threads

  1. JFileChooser remember the location
    By Mr tuition in forum AWT / Swing
    Replies: 3
    Last Post: 12-08-2007, 06:17 PM
  2. Replies: 2
    Last Post: 08-03-2007, 05:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •