Skip to content

Commit

Permalink
Merge pull request #42 from Ayu-hack/Ayu-hack-patch-1
Browse files Browse the repository at this point in the history
Swap Two Numbers
  • Loading branch information
Ayu-hack authored Oct 2, 2024
2 parents 91b40ac + d27dc78 commit 4e4e80f
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 4e4e80f

Please sign in to comment.