Results 1 to 7 of 7
  1. #1
    chitwood is offline Member
    Join Date
    Jan 2008
    Posts
    23
    Rep Power
    0

    Default Help me please!!!!!!!!!!!!

    I need some help with this program:

    Write a java program that prompts the user to enter five numbers. Calculate the average, the sum, and the product of these five numbers. Display the results in a format similar to this:

    The sum is 12
    The product is 44
    The average is 34

    Use Scanner for text input and System.out.println for the output.
    This is the code I have so far. Can someone please help me?


    import javax.swing.JOptionPane;

    public class MathData1 {
    public static void main(String[] args) {


    JOptionPane.showInputDialog(null,
    "Enter Integer 1",
    "Input Dialog",
    JOptionPane.QUESTION_MESSAGE);


    JOptionPane.showInputDialog(null,
    "Enter Integer 2",
    "Input Dialog",
    JOptionPane.QUESTION_MESSAGE);

    JOptionPane.showInputDialog(null,
    "Enter Integer 3",
    "Input Dialog",
    JOptionPane.QUESTION_MESSAGE);

    JOptionPane.showInputDialog(null,
    "Enter Integer 4",
    "Input Dialog",
    JOptionPane.QUESTION_MESSAGE);

    JOptionPane.showInputDialog(null,
    "Enter Integer 5",
    "Input Dialog",
    JOptionPane.QUESTION_MESSAGE);


    // Convert string to int
    int intValue = Integer.parseInt(intString);

    //Obtain Sum
    sum = "int 1" + "int 2" + "int 3" + "int 4" + "int 5";

    JOptionPane.showMessageDialog(null,
    "Sum"
    JOptionPane.INFORMATION_MESSAGE);


    }

    }

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    10

    Default

    the question asks for Scanner class not JOption.
    here's how to use it.
    Java Code:
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    Last edited by angryboy; 01-27-2009 at 06:04 AM. Reason: useless stuff removed
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,370
    Blog Entries
    1
    Rep Power
    23

  4. #4
    chitwood is offline Member
    Join Date
    Jan 2008
    Posts
    23
    Rep Power
    0

    Default Code Tags????????

    I dont understand? Are code tags (comments) for each section? or what ????
    I am new to this ( 2 weeks old)!!!!!!!!!!

    Thanks

    Chitwood

  5. #5
    chitwood is offline Member
    Join Date
    Jan 2008
    Posts
    23
    Rep Power
    0

    Default

    Is this a little better?



    import javax.swing.JOptionPane;

    public class MathData1 {
    public static void main(String[] args) {

    //Input 5 Numbers
    JOptionPane.showInputDialog(null,
    "Enter Integer 1",
    "Input Dialog",
    JOptionPane.QUESTION_MESSAGE);


    JOptionPane.showInputDialog(null,
    "Enter Integer 2",
    "Input Dialog",
    JOptionPane.QUESTION_MESSAGE);

    JOptionPane.showInputDialog(null,
    "Enter Integer 3",
    "Input Dialog",
    JOptionPane.QUESTION_MESSAGE);

    JOptionPane.showInputDialog(null,
    "Enter Integer 4",
    "Input Dialog",
    JOptionPane.QUESTION_MESSAGE);

    JOptionPane.showInputDialog(null,
    "Enter Integer 5",
    "Input Dialog",
    JOptionPane.QUESTION_MESSAGE);



    int 1int = Integer.parseInt(1String);
    int 2int = Integer.parseInt(2String);
    int 3int = Integer.parseInt(3String);
    int 4int = Integer.parseInt(4String);
    int 5int = Integer.parseInt(5String);



    // Convert string to int
    int intValue = Integer.parseInt(intString);

    //Obtain Sum
    doublesum = "int 1" + "int 2" + "int 3" + "int 4" + "int 5";

    JOptionPane.showMessageDialog(null,
    "Sum")
    JOptionPane.INFORMATION_MESSAGE;
    }

    }

  6. #6
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    10

    Default Code

    wrap the code in code tags. like this:
    XML Code:
    [CODE]
    codes here
    [/CODE]
    Last edited by angryboy; 01-27-2009 at 07:31 AM.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,370
    Blog Entries
    1
    Rep Power
    23

    Default

    Quote Originally Posted by chitwood View Post
    I dont understand? Are code tags (comments) for each section? or what ????
    I am new to this ( 2 weeks old)!!!!!!!!!!

    Thanks

    Chitwood
    Read FAQ page. All the information you want is there.

Posting Permissions

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