java program to swap two numbers using function

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

showing results for - "java program to swap two numbers using function"
Lisa
16 Apr 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}
Coraline
29 Jul 2017
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);
Paulina
19 Jul 2016
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 two values in javawrite a java program to swap two numbers using the third variable write java program to swap numbers by methodswap two values in javaswap two elements in javajava program to swap two numbers using methodswap two numbers in java using functionswapping two numbers in javawrite java program to swap numbers by methedswapping two numbers for loop javainteger swap fuction in java swap two numbers in java using methodstore two integer values swap the values javaswap two variables in javafunction two swap 2 numbers in javaswap numbers in java 22in java swap two halves if number is given 22how to swap two numbers without using a third variable in javaswapping two numbers in java 3fhow to swap two numbers in java without using third variableswap two numbers javawrite java programm to swap numbers by mothedsswap two integer value in javaswaping 2 numbers in javaswap two numbers without using third variable and arithmetic operator in javaswap numbers javawrite a java program to swap two numbers using the third variable 281 point 29java in built method to swap two numbersswapping the numbers in javaallintitle 3ajava program to swap two numberswrite a java program to swap two variables swap of two numbers in javajava program that swaps two numbers using temporary or third variablejava code that swaps their valuesjava program to swap two numbers without using third variableswap numbers in java if elseswap 2 numbers java functionswap numbers method javaswapping of two numbers in java using for loophow to swap two numbers using call by reference in javaswap numbers using temporary variables in javawrite a program to swap two integer number without using third variable in javaswap two numbers in java builtinjava program for swapping of two numbersswap 2 numbers without using 3rd variable javaswap two no in javaswap 2 number in javajava swap values two variablesswap two integers in javaswap two number in javaswap two integer in javaswap in javaswap 2 numbers javawrite a java program to swap two numbers without using third variable logic workshow to swap two variables in javaswap of two numbers in java using swap functionjava swap 2 number methodjava function to swap two numbersswap 28 29 numbers javaswap two number in java numberhow to swap integers in javaswap 2 integers in javajava swap integersfunction to swap two numbers in javahow to swap two numbersswapping two numbers javaswapping java programswap 2 numbers in javajava swap numberswapping numbers javajava in place swap intswap two numbers in java codeswap two numbers using third variable in javaswap two variable in javaswap two numbers in jabacan you make a function to swap two numbers in javaswap value of two numbers in javawap to swap two numbers without using third variable in javajava swap two variablesswap values in intwrite a java program to swap 2 numbersprogram to swap two numbers in javaswap two numbers using function in javaswapping of two numbers using function in javaexplanition how to sawp logic in javaswap to numbers in javafunction for swap two number in javajava program to swap two numbers using functionwrite a program to swap two numbers without using third variable in javaswap two numbers in javjava program to swapap numbersjava program to swap two numbersswapping two numbers without third variable java using for loop swapping of two numbers in javaswap 2 numbers without 3rd variable javawrite a program to swap two numbers without using third variable in java 3fjava swap 2 number by methodswap 2 int javawrite java program to swap numbers by mothersswapping of two numbers using third variable in javaswapping 2 numbers function in javahow many ways for swapping two numbers in java 3fhow to swap 2 value in javaswap two numbers in javaswap two numbers in java without using third variable in javaswap the numbers in javahow to read 2 user numbers and swap variable in javawap to swap two numbers in javajava method to swap two numbersswapping first 26 third 2c swap second 26 fourth digits javaswap code in javaa program to swap two numbers using the pass by value method in javaswap 3 numbers in java using one variablejava swap variable valuesswap number in javahow to swap two numbers in javaswap two numbers without using third variable in javaswapping of number using function in javajava program for swappping multiple timeshow to swap 3 numbers in javawrite a java program to swap two numbers using bitwise operator write a program to swap two numbers in javaswapping in java exaplanationswap to numbers using two class in javahow to swap 2 digits in javaswapping using third variable in javaswap two numbers javajava method swap integersswap two variables javajava swap values of 2 variableshow to switch or swap value of two variables in javaswap number javahow to swap number in javaswap 2 numbers inbuilt function in javamethod swap two numbers in javajava program to swap two numbers using bitwise operatorinbuilt method to swap two numbers javajava program to swap any 2 given numbersvalue swap in javaswap numbers using bitwise operator in javajava function for swapping two valuesswapping of two numbers without using third variable in javahow to swap values in javaswap variables javaswap the numbers inside number javaswapping of two numbers using function in java inbuilt functionswap two numbers in java geeksforgeeksswap two numbers in java using call by referencejava swap two integersswap 2 numbers java function gfgswap 3 numbers in javaswap two numbers in java with using third variableswap 2 variables in javaswap 2 numbers without using 3rd variable in javajava swap two numbersswap two numbers in java without using third variableswapping two numbers with third variable in java1 write a java program to swap two numbers using bitwise operator swap two values in java usin methidghow to swap numbers in javahow to swap 2 values in javawrite a program on swaping two numbers with out using third variable 3f in javahow to swap two numbers in java inbuilt functionjava how to swap two integerswrite a java program to swap two variableswrite a java program to swap two numbers using the third variable multi line swap a number in javaswaping values in javajava swap two intswitch two niumbers javaswapping numbers in javaswap the n numbers in javahow to swap two numbers in java without third variableswap numbers without using 3rd variable in javaswap two numbers without third variable in javaswap two int value in javajava program to swap two numbers using function