Results 1 to 2 of 2
  1. #1
    stephanie904 is offline Member
    Join Date
    Feb 2012
    Rep Power

    Default Help with Int and JOption Input dialog

    Im doing calculations for world population and I already have a formula and everything is working, but my question is when it asks to put "Enter years to see World Population Growth" what do i need to put for my int c when int c is unknown???? please help....

    Java Code:
    import java.util.Scanner;
    import javax.swing.JOptionPane;
    public class Population {
    	public static void main(String[] args) {
    	Scanner input = new Scanner( );
    	   int a = 7;
    	   double b = 1.0114;
               int c;
    	   double answer = c * a + b;
          JOptionPane.showMessageDialog(null, "Welcome to World population profile!\nCurrent world population of year 2012 is 7 billion\nand current world population growth rate of year 2012 is 1.14%"); 
    		String years =  
    		   JOptionPane.showInputDialog( "Enter years to see World Population Growth ");
    		String message = 
    		   String.format( "World Population Growth in %s years is " , years );
    		JOptionPane.showMessageDialog(null, message + answer);	

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: Help with Int and JOption Input dialog

    You've got things a little backwards in that you're trying to create your equation before you know the data to put in, and that won't work. Instead you will want to get your input first, and then use the inputted value in your equation.

Similar Threads

  1. Problem with Looping input dialog
    By kiraichi in forum New To Java
    Replies: 3
    Last Post: 02-11-2012, 09:14 PM
  2. How to create custom Input Dialog
    By Bab in forum SWT / JFace
    Replies: 2
    Last Post: 08-02-2009, 12:21 PM
  3. Creating a Number Input Dialog in SWT
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-02-2008, 07:53 PM
  4. Input Verification Dialog Demo
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-26-2008, 07:43 PM
  5. JOptionPane - input dialog
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-17-2007, 09:09 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