import java.util.Scanner;
public class Swap{
static int temp;
public static void swap(int num1,int num2){
System.out.println("Original nos are-Num1 : "
+ num1 + " Num2 : " + num2);
if(num1 > num2){
while(num1 > num2){
num1--;temp++;
}
while(temp >0){
temp--;num2++;
}
}
else{
while(num1 < num2){
num1++;temp--;
}
while(temp <0){
temp++;num2--;
}
}
System.out.println("Swaped nos are-Num1 : "
+ num1 + " Num2 : " + num2);
}
public static void main(String args[])
{
int num1,num2;
swap(new Scanner(System.in).nextInt(),
new Scanner(System.in).nextInt());
}
}
Sorry no correct answers this week!
No comments:
Post a Comment
Solution for this question?