java program to swap two numbers

Solutions on MaxInterview for java program to swap two numbers by the best coders in the world

showing results for - "java program to swap two numbers"
Diego Alejandro
13 Jul 2020
1import java.util.Scanner;
2// java swap function
3public class SwapTwoNumberDemo 
4{
5   int numOne, numTwo;
6   public void swapNum(SwapTwoNumberDemo stn)
7   {
8      int temp;
9      temp = stn.numOne;
10      stn.numOne = stn.numTwo;
11      stn.numTwo = temp;
12   }
13   public static void main(String[] args) 
14   {
15      SwapTwoNumberDemo obj = new SwapTwoNumberDemo();
16      try
17      {
18         Scanner sc = new Scanner(System.in);             
19         System.out.println("First number : ");
20         obj.numOne = sc.nextInt();
21         System.out.println("Second number : ");
22         obj.numTwo = sc.nextInt();
23         obj.swapNum(obj);
24         System.out.println("After swapping - numOne : " + obj.numOne + ", numTwo : " + obj.numTwo);
25         sc.close();
26      }
27      catch(Exception ex)
28      {
29         System.out.println("Exception: " + ex.toString());
30      }
31   }
32}
Laura
17 Mar 2016
1int a, b, c;
2a = 5;
3b = 3;
4System.out.println("Before SWAP a = " + a + ", b = " + b);
5c = a;
6a = b;
7b = c;
8System.out.println("After SWAP a = " + a + ", b = " + b);
Tino
02 Aug 2019
1int a = 5;
2int b = 6;
3
4int temp = a;
5a = b;
6b = temp;
7
8// now a is 6 and b is 5.
9
queries leading to this page
how to swap 2 digits in javaswap two int value in javahow to swap two numbers in javaswap two numbers in java without using third variable in javajava swap two variablesswap two values in javajava in place swap intswap two values in java usin methidgjava swap integersswap code in javajava swap variable valuesswapping of two numbers in javawrite a java program to swap two numbers using the third variable 281 point 29how to swap two numbersswap two numbers using function in javaswap two numbers in java geeksforgeeksswap two numbers in javaswap 3 numbers in java using one variableswap two numbers javaswap of two numbers in javawrite a java program to swap two numbers using the third variable write a java program to swap 2 numbersswap two integer value in javaswap number javaswapping java programswitch two niumbers javaswap 2 numbers inbuilt function in javawrite a program to swap two integer number without using third variable in javawrite a program to swap two numbers in javawrite a program to swap two numbers without using third variable in java 3fjava program to swap two numbers using methodswap in javajava program to swapap numbersjava program for swapping of two numbersvalue swap in javajava program to swap two numbers using functionhow to swap 2 values in javaswap two numbers in javhow to swap 2 value in javamethod swap two numbers in javaswapping numbers javaswaping values in javaswap 2 integers in javaswap 2 numbers in javaswap numbers method javaswap of two numbers in java using swap functionhow to swap 3 numbers in javaswap two variables javaswapping of two numbers without using third variable in javahow to swap two numbers without using a third variable in javaswaping 2 numbers in javaexplanition how to sawp logic in javainteger swap fuction in java write java program to swap numbers by mothershow to swap two numbers using call by reference in javajava program to swap two numbers without using third variablehow to swap values in javaswap numbers without using 3rd variable in javahow to swap two values in javaswap two numbers without using third variable and arithmetic operator in javafunction for swap two number in javacan you make a function to swap two numbers in javastore two integer values swap the values java 22in java swap two halves if number is given 22swap two numbers without third variable in javajava swap values two variablesswapping numbers in javaswap 3 numbers in javahow to swap integers in javaswap two numbers in java using functionjava swap 2 number by methodswapping of number using function in javaswapping of two numbers using function in javahow many ways for swapping two numbers in java 3f1 write a java program to swap two numbers using bitwise operator swap two integer in javaswapping of two numbers using function in java inbuilt functionjava program to swap two numbers using bitwise operatorprogram to swap two numbers in javaswap the n numbers in javajava function for swapping two valuesjava in built method to swap two numbersswap 28 29 numbers javaswapping two numbers in javaswap values in intfunction to swap two numbers in javawrite a java program to swap two numbers without using third variable logic worksswap 2 numbers without 3rd variable javaswap two numbers in jabaswap number in javaswapping using third variable in javaa program to swap two numbers using the pass by value method in javawrite java program to swap numbers by methedwap to swap two numbers without using third variable in javajava swap 2 number methodswap the numbers inside number javawrite java program to swap numbers by methodswap numbers javaswapping 2 numbers function in javajava swap two integersswap 2 number in javaswap two numbers using third variable in javaswapping the numbers in javaswapping in java exaplanationswap 2 numbers java function gfgwap to swap two numbers in javahow to swap two numbers in java inbuilt functionjava function to swap two numberswrite a program on swaping two numbers with out using third variable 3f in javaswap 2 numbers java functionwrite a program to swap two numbers without using third variable in javahow to read 2 user numbers and swap variable in javaswap two variable in javajava program for swappping multiple timesswapping two numbers for loop javaswap two numbers in java builtinswap the numbers in javajava how to swap two integershow to swap numbers in javaswap a number in javaswapping of two numbers in java using for loopswap two numbers in java using methodjava method to swap two numberswrite a java program to swap two variables java swap two intswap 2 numbers without using 3rd variable in javaswap to numbers using two class in javaswap two variables in javaswap value of two numbers in javajava program to swap two numbersswap 2 variables in javainbuilt method to swap two numbers javaswap to numbers in javaswap numbers using bitwise operator in javaswap numbers using temporary variables in javahow to swap two numbers in java without third variablejava program to swap any 2 given numbersjava method swap integersjava swap two numbersswap two number in javawrite a java program to swap two numbers using the third variable multi line swapping two numbers without third variable java using for loop how to swap number in javaswap two numbers without using third variable in javaswap variables javaswap two integers in javaswap numbers in java if elseallintitle 3ajava program to swap two numbersswap numbers in javahow to swap two numbers in java without using third variableswap 2 int javaswapping two numbers javawrite a java program to swap two numbers using bitwise operator swap 2 numbers javaswapping two numbers with third variable in javaswap two no in javaswapping first 26 third 2c swap second 26 fourth digits javajava code that swaps their valuesswap 2 numbers without using 3rd variable javaswap two elements in javafunction two swap 2 numbers in javaswap two numbers in java without using third variableswap two numbers in java using call by referenceswapping two numbers in java 3fwrite a java program to swap two variablesjava swap numberwrite java programm to swap numbers by mothedsswap two numbers in java with using third variablehow to swap two variables in javahow to switch or swap value of two variables in javajava swap values of 2 variablesswapping of two numbers using third variable in javaswap two numbers javajava program to swap two numbers