Swapping of two numbers in java with temporary variable

// swap three variables in java without using temporary variable
public class SwapThreeNumbersWithoutTemp
{
   static int num1, num2, num3;
   public static void main(String[] args) 
   {
      num1 = 30; num2 = 60; num3 = 90; 
      System.out.println("Before swapping three numbers: num1 = " + num1 + ", num2 = " + num2 + ", num3 = " + num3);
      swapWithoutTemporary();
      System.out.println("After swapping three numbers: num1 = " + num1 + ", num2 = " + num2 + ", num3 = " + num3);
   }
   static void swapWithoutTemporary() 
   { 
      num1 = num1 + num2 + num3; 
      num2 = num1 - (num2 + num3); 
      num3 = num1 - (num2 + num3); 
      num1 = num1 - (num2 + num3);  
   }
}

4
3
Lionel Aguero 33605 points

                                    public class Exercise15 {
  public static void main(String[] args) {
     // int, double, float
   int a, b;
   a = 15;
   b = 27;
   System.out.println("Before swapping : a, b = "+a+", "+ + b);
   a = a + b;
   b = a - b;
   a = a - b;
   System.out.println("After swapping : a, b = "+a+", "+ + b);
 }
 
}

4 (3 Votes)
0
4.38
8
Phoenix Logan 186120 points

                                    public class Main{public static void main(String[] args) {float a = 3.66f, b = 6.47f;System.out.println("a number " + a);System.out.println("b number " + b);float temp = a;a = b;b = temp;System.out.println("After swapping");System.out.println("a number " + a);System.out.println("b number " + b);}}

4.38 (8 Votes)
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 swap two values in java how to swap between 2 values placing in java write java programm to swap numbers by motheds how to swap two numbers in Java without using temp how to swap two numbers in java without using temporary variable swap tow var in java swapping two numbers without third variable in java swapping in java Swap numbers without using third variable in java swap two variables in java Write a java program to swap two numbers without using a third variable Write a Java program to swap two Strings using a third variable Write a program to swap two int variables without using a temporary variable in java Swapping of two numbers in java with temporary variable Write a program to swap two int variables using a temporary variable in java how to swap 2 value in java swap of two numbers in java using swap function how to write swap function in java without using third variable swapping in java swap numbers without temp in java how to change the values of two variables without swaping in java how to change the values of two variables without swapingin java wap to swap two numbers in java java program to swap two numbers without using third variable swap variables method in java swap vaibles method in java swapping two numbers without temporary variable in java swapping of two numbers without using third variable in java write a java program to swap 2 numbers write a program to swap two numbers without using third variable in java swap 2 number in java swap no without using third variable java swap a and be local variables java swap two numbers without using third variable in java swap function in java without third variable swap two integer in java Write a Java program to swap two variables. how to swap variables java how to swap two values in java swapping without using third variable in java java swap to variables java swap without third variable How do you swap two variables without using a third variable java swapping of two numbers in java without temporary variable How to swap two numbers without using temporary variable in java swap two numbers in java using call by reference swap three variables in java without using temporary variable java program to swap 2 numbers with using third variable Write a Java program to swap the value of two variables without using third variable swap two numbers in java how to swap two numbers in java without using third variable swap the values of two variables without using third variable in java how to swap two variables in java swap two strings without using third variable in java swapping of two numbers using third variable in java swap two numbers in java using function swap two numbers using function in java swap two no in java swap tw in java Swapping of two numbers in Java using for loop swapping two numbers for loop java swapping two numbers without third variable java java swap variables swap two numbers in java using method swap two numbers in java without using third variable java swap function for 2 variables swapping two numbers in java without using third variable swap variables java swap two integer class value in java swap primitive type java swap two int value in java swap 2 item java swap without third variable in java swap two numbers without third variable in java swapping without third variable in java java program swap of 2 variables without using third swapping of two numbers in java without operatoe swapping of two numbers in java swap 2 numbers without using 3rd variable java how to swap two variables without using third variable java. swapp using three variable in java how to swap the values of two objects in java how to swap the values of two variables while using objects in java swap two variables without using third variable in java an array swapp two elements using java? java how to swap two item how to swap variables in java how to swap two variables without using third variable in java variable swap function in java swap 2 variables java wap to swap two numbers without using third variable in java swapping variable in java using method swapping numbers without temp variable in java allintitle:swap three variables in java without using temporary variable how to switch or swap value of two variables in java swap 2 integers in java java swap two variables without using third swap two strings without using third variable in java java swap two variables swap method for swapping two elements in java swap two elements in java swap two values without third variable in java swap vaule with two variable on java swapping of two numbers using function in java how to make a swap function in java swap fuction in java swap two values jav swap values of two variables java can you make a function to swap two numbers in java java swap variable values
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