Computer Science, asked by ap0399654, 11 months ago

write a program in java to swap to string without using third variable​

Answers

Answered by charlie1505
1

Answer:

public class SwapWithoutTemp {

public static void main(String args[]) {

String a = "hi";

String b = "hello";

System.out.println("Before swap: " + a + " " + b);

a = a + b;

b = a.substring(0, a.length() - b.length());

a = a.substring(b.length());

System.out.println("After : " + a + " " + b);

}

}

Answered by atrs7391
0

package com.company;  

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

       Scanner sc = new Scanner (System.in);

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

       String a = sc.nextLine();

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

       String b = sc.nextLine();

       

           a = a+b;

           b = a-b;

           a = a-b;

     

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

   }

}

Similar questions