Saved Bookmarks
| 1. |
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 |
|
Answer» ong>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); } } |
|