hope you can help

hi there, im learning C++ and Java in tandum, this is a java question but i trust you guys so much i dont want to have to sign up to a new forum to get an answer, and you guys have never let me down.

i made an application that took 2 user input ints and printed out the sum with printf.
the book now is telling me to change the program to work with JOptionPane; class instead, so asking via a dialog box for the 2 ints and displaying the sum in a messagebox, this is what i'vr written bu can't work out, tried for ages befotre i came here, hopefully yo ucan help me out! once i know this i think i'll be good to go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import javax.swing.JOptionPane;

public class Additions
{
   
   public static void main( String args[] )
   {
      
	  int sum; 
	  String name;
	  String name2;
	  
      String name = // return type string, pane asking for name
			JOptionPane.showInputDialog( "What is the first integer?" );

      String name2 = // return type string, pane asking for name
			JOptionPane.showInputDialog( "What is the second integer?" );
			
	  sum = name + name2;

      
	  int sum = 
		   String.format( "Sum is %d\n", sum );

   } 

} 
Last edited on
i finally fixed it, thanks anyway
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import javax.swing.JOptionPane;

public class Additions
{
   
   public static void main( String args[] )
   {
      
	
	  
     String number1 =
	        JOptionPane.showInputDialog( "Enter first integer: " );
	int sum1 = Integer.parseInt(number1);
			

     String number2 =
	        JOptionPane.showInputDialog( "Enter second integer: " );
	int sum2 = Integer.parseInt(number2);
			
			  
	  String sum = 
		   String.format( "Sum is %d\n", sum1+sum2 );
		   
	  JOptionPane.showMessageDialog( null, sum );

   } 

} 
Topic archived. No new replies allowed.