java program to swap two numbers

import java.util.Scanner;
// java swap function
public class SwapTwoNumberDemo 
{
   int numOne, numTwo;
   public void swapNum(SwapTwoNumberDemo stn)
   {
      int temp;
      temp = stn.numOne;
      stn.numOne = stn.numTwo;
      stn.numTwo = temp;
   }
   public static void main(String[] args) 
   {
      SwapTwoNumberDemo obj = new SwapTwoNumberDemo();
      try
      {
         Scanner sc = new Scanner(System.in);             
         System.out.println("First number : ");
         obj.numOne = sc.nextInt();
         System.out.println("Second number : ");
         obj.numTwo = sc.nextInt();
         obj.swapNum(obj);
         System.out.println("After swapping - numOne : " + obj.numOne + ", numTwo : " + obj.numTwo);
         sc.close();
      }
      catch(Exception ex)
      {
         System.out.println("Exception: " + ex.toString());
      }
   }
}

0
8
Mrinmoy 110 points

                                    int a, b, c;
a = 5;
b = 3;
System.out.println("Before SWAP a = " + a + ", b = " + b);
c = a;
a = b;
b = c;
System.out.println("After SWAP a = " + a + ", b = " + b);

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
swap two numbers without using third variable and arithmetic operator in java write a java program to swap two numbers without using third variable logic works swap two values in java how to swap number in java write a program to swap two numbers without using third variable in java swap 2 int java swap 2 numbers without using 3rd variable in java swapping of number using function in java write java program to swap numbers by method write java program to swap numbers by methed write java program to swap numbers by mothers write java programm to swap numbers by motheds swap two number in java how to swap two numbers in java without third variable java swap number swap two elements in java "in java swap two halves if number is given" swap two numbers in java without using third variable how to swap 2 value in java swap of two numbers in java using swap function swap of two numbers in java swap two numbers in java geeksforgeeks swap number java how to swap two numbers using call by reference in java write a java program to swap two variables swapping the numbers in java wap to swap two numbers in java java program to swap two numbers without using third variable swap two integers in java write a java program to swap 2 numbers swapping two numbers java java swap values of 2 variables write a java program to swap two numbers using bitwise operator. java program to swapap numbers swap 2 number in java write a program to swap two numbers in java swap two integer in java Write a Java program to swap two variables. java swap two variables swapping of two numbers using third variable in java how to swap two values in java swap to numbers in java swap a number in java java program to swap two numbers using method swap two numbers in java using method swap two numbers using function in java swap 2 numbers java function gfg swap 2 numbers java function swap 2 numbers java swap two numbers java swap two numbers without third variable in java function for swap two number in java swap two variables java how to swap two variables in java Write a Java Program to swap two numbers using the third variable. (1 Point) how to swap two numbers in java without using third variable Write a Java Program to swap two numbers using the third variable.Multi Line swap two no in java how to swap integers in java Swapping of two numbers in Java using for loop swapping two numbers for loop java swapping two numbers without third variable java using for loop swap() numbers java method swap two numbers in java swap numbers in java if else swapping of two numbers in java how to swap two numbers in java inbuilt function java swap values two variables swap two Integer value in java swap two int value in java swap two numbers in java with using third variable how to swap two numbers in java swap 2 numbers without using 3rd variable java allintitle:Java program to swap two numbers swapping of two numbers without using third variable in java swap two numbers without using third variable in java swap two numbers using third variable in java java how to swap two integers java swap two numbers swapping numbers java Java program to swap two numbers using bitwise operator swap numbers without using 3rd variable in java store two integer values swap the values java wap to swap two numbers without using third variable in java java method to swap two numbers how to switch or swap value of two variables in java inbuilt method to swap two numbers java swap two numbers in java builtin swap 2 integers in java java function to swap two numbers swap two numbers in java using function Write a program to swap two integer number without using third variable in java java program to swap any 2 given numbers swap two numbers in java using call by reference swap numbers method java function to swap two numbers in java program to swap two numbers in java swapping of two numbers using function in java inbuilt function swapping of two numbers using function in java how to swap numbers in java how to read 2 user numbers and swap variable in java Java program to swap two numbers using function explanition how to sawp logic in java swap code in java swap number in java swap numbers using temporary variables in java can you make a function to swap two numbers in java java program for swappping multiple times swapping java program swapping using third variable in java java swap integers how to swap 2 digits in java function two swap 2 numbers in java how to swap two numbers java swap two integers swapping two numbers in java swap values in int swap 3 numbers in java using one variable swap 2 numbers in java swap in java swapping in java exaplanation switch two niumbers java swap to numbers using two class in java swap numbers in java swapping first & third, swap second & fourth digits java swap two numbers in java swap two numbers java swapping numbers in java Swap two variables in java swap variables java java swap variable values java program to swap two numbers
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source