Results 1 to 4 of 4
  1. #1
    kiraichi is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Problem with Looping input dialog

    hi, i have some problem with looping input dialog, what i want it look like is, the input dialog will popup 10 times, so i can to enter the worker age, and then, the 11st message dialog, its shows the average of the 10 worker, but the problem is, when i enter the first worker, then, it didnt loop it. can somebody look for it? heres my source

    Java Code:
    /**
     * @(#)avava.java
     *
     * avava application
     *
     * @author
     * @version 1.00 2012/2/12
     */
    
    import javax.swing.JOptionPane;
    public class avava {
    
        public static void main(String[] args) {
        	String worker;
        	String txt= "";
    
        	for (int i=1 ; i<= 10; i++) {
    
        		for(int j=1 ;j <= i; j++){
    
        			worker = JOptionPane.showInputDialog("Please enter worker age :");
        			JOptionPane.showMessageDialog(null,"You entered: " + worker);
    
    
    int k1= Integer.parseInt(worker);
    
    int resources1= k1 / j;
    
    String txt1= txt + resources1;
    
    
    JOptionPane.showMessageDialog(null,"The average age of worker is:" + resources1);
    JOptionPane.showMessageDialog(null, "Bye!");
    System.exit(0);
    
        		}
        	}
        }
    }

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

    Default Re: Problem with Looping input dialog

    Your code formatting makes the code hard to read and understand. Lines 25 - 35 should be indented past the {} that enclose them.

    When is the System.exit(0) statement executed? Is it inside of the loops?
    Look at where the ending }s are located.

  3. #3
    kiraichi is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Re: Problem with Looping input dialog

    the System exit should be stop when the total average is showed. but, it shows the wrong number. >.<"

    tq for ur reply anyway

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

    Default Re: Problem with Looping input dialog

    If you edit your code and change the indentations to show the nesting of statements within pairs of {}, it will be easier to see what the code is doing.

Similar Threads

  1. How to create custom Input Dialog
    By Bab in forum SWT / JFace
    Replies: 2
    Last Post: 08-02-2009, 01:21 PM
  2. Creating a Number Input Dialog in SWT
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-02-2008, 08:53 PM
  3. Input Verification Dialog Demo
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-26-2008, 08:43 PM
  4. JOptionPane - input dialog
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-17-2007, 10:09 AM
  5. Multiple Line Input Dialog Box
    By johnt in forum AWT / Swing
    Replies: 2
    Last Post: 05-31-2007, 10:30 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
  •