Results 1 to 4 of 4
- 02-11-2012, 08:16 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
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); } } } }
- 02-11-2012, 08:38 PM #2
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.
- 02-11-2012, 09:05 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 2
- Rep Power
- 0
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
- 02-11-2012, 09:14 PM #4
Similar Threads
-
How to create custom Input Dialog
By Bab in forum SWT / JFaceReplies: 2Last Post: 08-02-2009, 12:21 PM -
Creating a Number Input Dialog in SWT
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 07:53 PM -
Input Verification Dialog Demo
By Java Tip in forum javax.swingReplies: 0Last Post: 06-26-2008, 07:43 PM -
JOptionPane - input dialog
By Java Tip in forum Java TipReplies: 0Last Post: 12-17-2007, 09:09 AM -
Multiple Line Input Dialog Box
By johnt in forum AWT / SwingReplies: 2Last Post: 05-31-2007, 09:30 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks