Computer Science, asked by Anonymous, 4 months ago

Write a program to input two unequal numbers. Display the numbers after swapping their values in
the variables without using a third variable.
Sample Input: a=23, b=56
Sample Output: a=56, b=23


Anonymous: Java or python
Anonymous: Illogical answers will be reported

Answers

Answered by atrs7391
4

Answer:

import java.util.Scanner;

public class Answer11b {

   public static void main(String[] args) {

       Scanner sc = new Scanner (System.in);

       System.out.println("Enter Number a:");

       int a = sc.nextInt();

       System.out.println("Enter Number b:");

       int b = sc.nextInt();

       if (a!=b){

           a = a+b;

           b = a-b;

           a = a-b;

       }

       System.out.println("a = "+a+"    b = "+b);

   }

}


anindyaadhikari13: Good but no need of giving any condition. It works for all cases.
atrs7391: I know, actually I am the one who wants everything perfect and best So...
atrs7391: btw thanks for following
Similar questions