Program to swap two numbers

Java program to swap two numbers

public class SwapNumbers {

    public static void main(String[] args) {

        float first = 1.20f, second = 2.45f;

        System.out.println("--Before swapping--");
        System.out.println("First number = " + first);
        System.out.println("Second number = " + second);

        
        float temporary = first;
        
        first = second;

        second = temporary;

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

}

Comments

Popular posts from this blog

Java Variables and Datatype

Java Fundamentals

Naming standards in JAVA