Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

swap two numbers without third variable

int a=4;
int b=5;
a=a+b; // 4 + 5 = 9
b=a-b; // 9 - 5 = 4
a=a-b; // 9 - 4 = 5
Comment

swap 2 numbers without using 3rd variable

a=10;
b=20;
a=a+b;//a=30 (10+20)    
b=a-b;//b=10 (30-20)    
a=a-b;//a=20 (30-10)    
Comment

swapping of two numbers

 #include <iostream>  
using namespace std;  
int main()  
{  
int a=5, b=10;      
cout<<"Before swap a= "<<a<<" b= "<<b<<endl;      
a=a*b; //a=50 (5*10)    
b=a/b; //b=5 (50/10)    
a=a/b; //a=10 (50/5)    
cout<<"After swap a= "<<a<<" b= "<<b<<endl;      
return 0;  
}  
Comment

swap of two numbers without using third variable

a=20;
b=40;
a=a+b;  
b=a-b;
a=a-b;  
Comment

how to swap 2 numbers without 3rd variable

int a = 3;
int b = 5;
a = b*a;
b = a/b
a = a/b
Comment

How to swap two numbers

// Method 1: With temporary variable
temp = A
A = B
B = temp
// without temporary variable
// Method 2: Addition and subtraction
A = A + B
B = A - B
A = A - B
// Method 3: Muitply and Divide
A = A * B
B = A / B
A = A / B
Comment

swapping data of two variable without third one

X= 25 (First number), Y= 23 (second number)
Swapping Logic:
X = X + Y = 25 +23 = 48
Y = X - Y = 48 - 23 = 25
X = X -Y = 48 - 25 = 23
and the numbers are swapped as X =23 and Y =25.
Comment

Swapping Two Numbers Using Third Variable

   public static void main(String[] args) {
        int x = 10;
        int y = 20;
        int temp;

        temp = x;
        x = y;
        y = temp;

        System.out.println("x:"+x  +" y:" + y);
    }
Comment

swap two numbers without using third variable

var a=window.prompt('enter a number')var b=window.prompt('enter a number')var a=a+b;var b=a-b;var a=a-b;console.log ("value of a is",a);console.log('value of b is',b);
Comment

swap two numbers

    public static void main(String[] args) {
        int x = 10;
        int y = 20;
        
        x=x+y;
        y=x-y;
        x=x-y;

        System.out.println("x:"+x+" y:"+y);
    }
Comment

swap two number

Route::get('/foo', function (AppFoo $foo) {
    return $foo->hello(); // Hello World
});
Comment

Swapping two variable without initializing the third variable

#include <iostream>
using namespace std;
int main()
{
    int first_number = 10, last_number = 20;
    first_number = first_number + last_number;
    last_number = first_number - last_number;
    first_number = first_number - last_number;
    cout << first_number << " " << last_number << endl;
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Java :: enhanced for loop arraylist 
Java :: java packages example 
Java :: how to find mongo java driver version 
Java :: java assert 
Java :: android studio int ot string 
Java :: Java telegram bot dependency 
Java :: linear serach in java 
Java :: hash map java 
Java :: java indexof nth occurrence 
Java :: import image icon 
Java :: observer design pattern 
Java :: java change hashmap value 
Java :: stringbuilder in java 
Java :: java how to split a string to array 
Java :: room insert and return id 
Java :: string length java 
Java :: java tree traversal 
Java :: java sort reverse lambda 
Java :: java comparator comparing 
Java :: Java Iterating through LinkedList 
Java :: No enclosing instance of type Foo is accessible. Must qualify the allocation with an enclosing instance of type Foo (e.g. x.new A() where x is an instance of Foo 
Java :: java spring mvc 
Java :: what is deserialization in java 
Java :: javafx combobox cell 
Java :: stream reduce stringbuilder 
Java :: factorial recursion java 
Java :: intergers are appearing as string in Json 
Java :: open cv for java 
Java :: countdown timer with seekbar 
Java :: null check in line java 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =