1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | package com.kota.java; public class SwapNumbers { public static void main(String[] args) { int num1 = 10; int num2 = 20; System.out.println("Before Swapping"); System.out.println("Value of num1 is :" + num1); System.out.println("Value of num2 is :" +num2); //swap the value swap(num1, num2); } private static void swap(int num1, int num2) { int temp = num1; num1 = num2; num2 = temp; System.out.println("After Swapping"); System.out.println("Value of num1 is :" + num1); System.out.println("Value of num2 is :" +num2); } } /* Output : Before Swapping Value of num1 is :10 Value of num2 is :20 After Swapping Value of num1 is :20 Value of num2 is :10*/ |
It's all about Java development. A place mainly for java programmers.
Saturday, 10 March 2012
Swap Numbers using third variable
Subscribe to:
Post Comments (Atom)
Hi
ReplyDeleteI faced one interview question how to write program for string words reverse.
Like input : "Hello java world"
Output : "world java Hello"
thanks
kesav
Can you please write a program for me.
ReplyDelete