Skip to content

Commit

Permalink
Swap Two Numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayu-hack authored Oct 2, 2024
1 parent 91b40ac commit d27dc78
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Swap Two Numbers
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class SwapNumbers {

public static void main(String[] args) {

float first = 1.20f, second = 2.45f;

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

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

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

// Value of temporary (which contains the initial value of first) is assigned to second
second = temporary;

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

0 comments on commit d27dc78

Please sign in to comment.