Saturday, July 30, 2022

Swap Two Numbers Using JOptionaPane in Java

A simple program that I wrote that will ask the user to give two numbers and then the program will swap the arrangement of two numbers using JOptionPane in Java programming language.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

Please subscribe to my channel  https://www.youtube.com/channel/UCOs-lpOoIeJoh6gpJthPoGg

=================================================


Want to support my channel?

GCash Account

Jake Pomperada


09173084360


Paypal

https://paypal.me/jakerpomperada


Patreon

https://www.patreon.com/jakerpomperada


Thank you very much for your support.





Program Listing

package demo;

import javax.swing.JOptionPane;

public class Activity_No_One {

public static void main(String[] args) {
// TODO Auto-generated method stub
// obtain user input from JOptionPane input dialogs

      String one = 

         JOptionPane.showInputDialog( "Enter first integer" );

      String two =

          JOptionPane.showInputDialog( "Enter second integer" );
      
      // convert String inputs to int values for use in a calculation

      int a = Integer.parseInt(one); 

      int b = Integer.parseInt(two);
      
      int temp=0;

      
      // display result in a JOptionPane message dialog

      JOptionPane.showMessageDialog( null,  "Value No. 1 : " + a + "\n" 
      + "Value No. 2 : " + b, "Before Swapping", JOptionPane.INFORMATION_MESSAGE );
      
      /*swapping */  
       temp = a;  
       a = b;  
       b = temp;  
       
       
       JOptionPane.showMessageDialog( null,  "Value No. 1 : " + a + "\n" 
          + "Value No. 2 :  " + b, "After Swapping", JOptionPane.INFORMATION_MESSAGE );

}

}

No comments:

Post a Comment