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)
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)
swap two variables without temporary java
import java.*;
class noTemp {
public static void main(String a[])
{
int x = 10;
int y = 5;
x = x + y;
y = x - y;
x = x - y;
System.out.println("After swaping:"
+ " x = " + x + ", y = " + y);
}
}
swap 2 integers without using temporary variable
using System;
class MainClass {
public static void Main (string[] args) {
int num1 = int.Parse(Console.ReadLine());
int num2 = int.Parse(Console.ReadLine());
num1 = num1 + num2;
num2 = num1 - num2;
num1 = num1 - num2;
Console.WriteLine("After swapping: num1 = "+ num1 + ", num2 = " + num2);
Console.ReadLine();
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us