Java Program - 05 - Write a Java program to swap two numbers using third variables.
Enter x ::
500
Enter y ::
100
Before Swapping....
x = 500
y = 100
After Swapping....
x = 100
y = 500
//Java Program - 05 - Write a Java program to swap two numbers using third variables. //Using Scanner Class import java.util.Scanner; public class StudyViral_05 { public static void main(String args[]) { int x, y, temp; Scanner in = new Scanner(System.in); System.out.println("Enter x :: "); x = in.nextInt(); System.out.println("Enter y :: "); y = in.nextInt(); System.out.println("Before Swapping...."); System.out.println("x = "+x+"\ny = "+y); temp = x; x = y; y = temp; System.out.println("After Swapping...."); System.out.println("x = "+x+"\ny = "+y); } }Output ::
Enter x ::
500
Enter y ::
100
Before Swapping....
x = 500
y = 100
After Swapping....
x = 100
y = 500
0 comments:
Post a Comment