Computer Science, asked by viddhyanidhi4774, 10 months ago

Write a program in Java to input two numbers display the numbers after swapping them by using a third variable.
Sample Input a = 95, b = 45 Sample Output a = 45, b = 95

Answers

Answered by Oreki
12

import java.util.Scanner;

public class Swap {

public static void main(String[ ] args) {

Scanner sc = new Scanner(System.in);

System.out.println("Enter two numbers to be swaped - ");

int a = sc.nextInt( ),

b = sc.nextInt( ),

temp = a;

System.out.printf("Before - %n a - %d%n b - %d%n", a, b);

// Swapping numbers

a = b;

b = temp;

System.out.printf("After - %n a - %d%n b - %d%n", a, b);

}

}

Similar questions