Results 1 to 2 of 2

Thread: One line causing code to fail.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    19

    One line causing code to fail.

    The last line before the exit is causing a problem, as far as I can see, everything is right (calculations, variables, etc...) when you take out the division line, the problem gives you your two numbers, but won't divide them in that line of code, why is that?

    Code:
    import javax.swing.JOptionPane;
    
    public class Problem2
    {
    	public static void main(String [] args)
    	{
    		double integer_one, integer_two;
    		String number_one, number_two, Product;
    
    		number_one = JOptionPane.showInputDialog(null,"Please enter your weekly salary:");
    		integer_one = Integer.parseInt(number_one);
    
    		number_two = JOptionPane.showInputDialog(null,"Please enter your hours worke:");
    		integer_two = Integer.parseInt(number_two);
    
    		JOptionPane.showMessageDialog(null, number_one, "Weekly Salary",JOptionPane.OK_CANCEL_OPTION);
    		JOptionPane.showMessageDialog(null, number_two, "Hours worked",JOptionPane.OK_CANCEL_OPTION);
    
    		JOptionPane.showMessageDialog(null,"Hourly Pay" + integer_one / integer_two ,JOptionPane.OK_CANCEL_OPTION);
    
    		System.exit(0);
    	}
    }
    Last edited by Squirrel RJ; Feb 27th, 2006 at 08:56 PM.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: One line causing code to fail.

    Change the last line to:
    Code:
    JOptionPane.showMessageDialog(null
                                      , "Hourly Pay" + (integer_one / integer_two)
                                      , "Payment", JOptionPane.OK_CANCEL_OPTION) ;
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

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



Click Here to Expand Forum to Full Width