Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

I need help converting int to double

807606Feb 5 2007 — edited Feb 5 2007
OK so i just started taking this begginer Java Class. My professor asked us to write a GUI program thar asks a user to input 2 number and then output the sum. I was able to do that fine. BUt now she has asked use to convert the integers to double... How would i do that? here is my code:
import javax.swing.JOptionPane; // import class JOptionPane

public class Addition2 
{
   // main method begins execution of Java application
  
 public static void main( String args[] )
   {
   	   String number;
   	   	int num1;
   	   	int num2;
   	   	int sum; 	   	  	
   	   	
   	   	// Read first number	
        number =
      	JOptionPane.showInputDialog("Please Enter First number:");
        num1 = Integer.parseInt(number);
      	
      	// Read second number     
        number = 
      	JOptionPane.showInputDialog("Please Enter Second number:");
      	num2 = Integer.parseInt(number);
      	
      	//Conver numbers from string to parseint    	
          	     		
      // Compute SUM
      sum = num1 + num2; 

	String message =
		String.format("The sum of the numbers are: %d", sum);
    
    JOptionPane.showMessageDialog( null, message );
   
   }
   } // end method main
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 5 2007
Added on Feb 5 2007
18 comments
516 views