Saved Bookmarks
| 1. |
Write a java programs for swapping of two numbers using third variable. |
| Answer» IMPORT java.util.*; CLASS Swap_With { public static void main(String[] args) { int X, y, t; Scanner sc = new Scanner(System.in); System.out.println("Enter the value of X and Y"); x = sc.nextInt(); y = sc.nextInt(); System.out.println("before swapping numbers: "+x +" "+ y); t = x; x = y; y = t; System.out.println("After swapping: "+x +" " + y); System.out.println( ); } } Explanation:This will ACCEPT two numbers and then will swap the numbers | |