Sunday 7 August 2022

Swap two numbers with and without using temporary variable


Swap two numbers without using temporary variable

public class SwappingNumbers {

    public static void main(String[] args) {

        float first = 10.0f, second = 14.5f;

        System.out.println("First number is " + first);
        System.out.println("Second number is " + second);

        first = first - second;
        second = first + second;
        first = second - first;

        System.out.println("--Swapping numbers--");
        System.out.println("First number = " + first);
        System.out.println("Second number = " + second);
    }
}

Now lets try to swap the numbers without using the temp variable


public class SwappingNumbers {

    public static void main(String[] args) {

        float first = 11.20f, second = 12.45f;

        // Value of the first is assigned to temporary
        float temporary = first;

        // Value of the second is assigned to first
        first = second;

        // Value of temporary is assigned to the second now
        second = temporary;

        System.out.println("First number = " + first);
        System.out.println("Second number = " + second);
    }
}

************************************************

✍️AUTHORLinkedIn Profile

************************************************

Learn (API-Microservice)Testing+ Selenium UI Automation-SDET with Self Paced Videos prepared by FAANG employee and LIVE Doubt Session 

SDET TRANING VIDEOS AVAILABLE with Live Doubt Session(course-1 below,API TRaining Videos With Class Notes and Coding Set) and (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122. 
This includes classnotes, 300+ interview questions, 3 projects, Java Coding question set for product companies along with career guidance from FAANG employee for Automation and SDET.

For more details whatsapp 

Check below link for question and answers with the code:

Top API Interview Question 1-10

Top API INterview Questions 11-20 

Top API AUTOMATION Interview Q&A - 21-30

*************************************************

SeleniumWebdriver Automation Testing Interview Questions:

https://automationreinvented.blogspot.com/search/label/SeleniumWebdriver

API Testing Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Rest-API

Kubernetes Interview Question Set

https://automationreinvented.blogspot.com/search/label/Kubernetes

Docker Interview Question Set

https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

Linux Interview question Set

https://automationreinvented.blogspot.com/search/label/Linux

Automation Testing/SDET Framework Design

https://automationreinvented.blogspot.com/search/label/FrameworkDesign

Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java

GIT Interview Question Set:

https://automationreinvented.blogspot.com/search/label/GIT

Coding Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Coding%20Questions

Mobile Testing Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

Python Interview Question Set for QAE - SDET - SDE:

https://automationreinvented.blogspot.com/search/label/Python




No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

API Status Codes with examples for QA-Testers

  🔺 LinkedIn: https://www.linkedin.com/in/sidharth-shukla-77b53145/ 🔺 Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 🏮In API testing, it...