Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; // for user input
- public class Swap2 {
- /**
- * Program : Swap2.java
- * Purpose : Swap two numbers, without using a third variable
- * Creator : Chris Clarke
- * Created : 14.06.2013
- */
- public static void main(String[] args) {
- int x, y;
- Scanner scan = new Scanner(System.in);
- System.out.print("Enter value for x: ");
- x = scan.nextInt();
- System.out.print("Enter value for y: ");
- y = scan.nextInt();
- x += y;
- y = x-y;
- x -= y;
- System.out.println("Swapped! x is now "+x);
- System.out.println("and y is now "+y);
- }//end main
- }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement