Results 1 to 3 of 3
  1. #1
    dienesh77 is offline Member
    Join Date
    Feb 2011
    Posts
    32
    Rep Power
    0

    Default I cant get this Message dialog to appear.

    import javax.swing.JOptionPane;

    public class calculateMeanAndSD {

    static double marks;
    static double mean;

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    for ( int counter = 0; counter < 10; counter++ ) {

    marks = Double.parseDouble(JOptionPane.showInputDialog("En ter marks to compute Mean and Standard Deviation: "));
    calculateMean();

    }

    }
    public static void calculateMean() {
    double sum = 0;
    int j = 0;

    sum += marks;
    mean = sum / 10;
    j++;

    if (j == 10) {
    JOptionPane.showMessageDialog(null, "The Mean of the marks entered is: "+mean);
    } else {
    System.out.print("");
    }

    }

    }
    =========================================
    I cannot get this : " JOptionPane.showMessageDialog(null, "The Mean of the marks entered is: "+mean) " to appear.

    much help would be appreciated. thanks

  2. #2
    Ruuhkis is offline Member
    Join Date
    Feb 2011
    Posts
    19
    Rep Power
    0

    Default

    it will appear only if j's value is 10

  3. #3
    Stamoulohta is offline Member
    Join Date
    Mar 2011
    Posts
    26
    Rep Power
    0

    Default

    I am very very new to java but I would try:
    Java Code:
    if(j.equals(10))
    and printing j in the else clause to see what it's value is..
    Java Code:
    else {
    System.out.print(j);
    }
    Other than that, I don't see how the value of j would ever be greater than 1 since every time you call calculateMean() you initiate it with 0 value... That being said, I would try passing "counter" as an argument to calculateMean()

    PS: I am in the "Hello World" stage but I waned to see if I can make anything out of java code... I hope either that I helped you a bit or at least I didn't get on your nerves...

    Cheers!
    Last edited by Stamoulohta; 03-07-2011 at 11:07 AM. Reason: New Idea

Similar Threads

  1. show Message Dialog
    By akritc in forum AWT / Swing
    Replies: 7
    Last Post: 06-10-2010, 03:49 PM
  2. Replies: 6
    Last Post: 06-04-2010, 09:43 PM
  3. Replies: 13
    Last Post: 03-20-2010, 02:03 AM
  4. Example of SWT Dialog
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-09-2008, 01:01 PM
  5. JOptionPane - message dialog
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-17-2007, 10:11 AM

Posting Permissions

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