You are here: Home / Topics / Program to read data using InputDialog and display data using MessageDialog in Java

Program to read data using InputDialog and display data using MessageDialog in Java

Filed under: Java on 2024-03-01 06:51:27

// Program to read data using InputDialog and display data using MessageDialog.

import javax.swing.JOptionPane;

class  Swap4
{
public static void main( String args[ ] )
{
 int  a=0, b=0, t;

 a = Integer.parseInt(JOptionPane.showInputDialog("Enter first Number : " ));
 b = Integer.parseInt(JOptionPane.showInputDialog("Enter second Number : " ));

 JOptionPane.showMessageDialog( null, " Before Swapping : " + a + "   " + b );
 
 a = a + b;
 b = a - b;
 a = a - b;
 
 JOptionPane.showMessageDialog( null, " After Swapping : " + a + "   " + b );
}
}


Output:

See output runtime with diaog


About Author:
G
Geetam     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.