Menu

How to swap two String variables without using the third variable?

We are going to see how to swap two variable of type String without using any third or temporary variable. 
This is very frequent question asked by interviewer in any Java technical interview.

Below is a simple java program to swap two String variables a and b.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
package jorvee;

public class SwapTwoStringVariableWithoutUsingTheThirdVariable {

 public static void main(String[] args) {
  String a="swap", b="two numbers";
  a= a+b;
  b= a.substring(0, a.length() - b.length());
  a= a.substring(b.length());
  System.out.println("After swaping value of a is: "+a);
  System.out.println("After swaping value of b is: "+b);

 }

}

Output:

After swaping value of a is: two numbers
After swaping value of b is: swap

How to calculate interest on Saving account?

Formula to calculate the interest on Saving account: 
Amount * ROI / 100 * No Of Days / 365

Here Amount is the base amount available in your account.
ROI: Rate of interest which your bank is providing you on your saving account.  
No of days: Total number of days that amount remain in your saving account.

lets take an example:
I have a saving account in state bank of India. State bank gives 4% rate of interest annually on saving accounts and I kept rupees 100,000 in my saving account for 15 days. Then how much interest I will earn from this.

Amount: 100000
ROI: 4
No of Days: 15 
lets calculate using the formula:
Total interest = Amount * ROI / 100 * No Of Days / 365
= 100000 * 4/100 * 15/365
 = 164.38
Total interest a account holder will earn 164.38 rupees in 15 days on the amount of rupees 100000. 

Khaki : Mein kyun hun, kab se hun, kab tak hun aur kya hun mein?

Isi talash-o-tasawwur mein kho gaya hun mein; (Asghar Gondvi) Mein kyun hun, kab se hun, kab tak hun aur kya hun mein? Tamam daftar-e-hikmat ulat gaya hun mein Magar khula na abhi tak kahan hun kya hun mein Rahi hai khak ke zarron mein bhi chamak meri Kabhi kabhi to sitaaron main mil gaya hun mein Uda hun jab to liya hai falak pe dam ja kar Zamin ko tod gaya hun jo reh gaya hun mein (Asghar Gondvi) Isi talash-o-tasawwur mein kho gaya hun mein Kahin zehmat kahin rahat kahin shifa hun mein Kahin abid kahin munkir kahin fana hun mein Kahin aajiz kahin sarkash kahin raza hun mein Kahin munsif kahin mujrim kahin saza hun mein Kahin rahbar kahin rahzan kahin dagha hun mein Kahin dilbar kahin aashiq kahin wafa hun mein Kahin saaqi to kahin rind-e-parsaa hun mein Kahin hamdard kahin dard-e-ladawa hun mein Mere wajood main hai khair-o-shar ki aagaahi Kabhi wali kabhi iblees se gira hun main Isi talash-o-tasawwur mein kho gaya hun mein Bashar ke roop main ik raaz-e-Kibriya hun mein Samajh sake na farishtay keh aur kya hun mein Hayat-o-maot ke jalwe hain meri hasti main Mein intaha bhi hun aur apni ibtida hun mein Pata lagaye koi kya mere patay ka pata Mere patay ka pata hai keh la-pata hun mein (Bedam Shah Warsi & Muhammad Samie) Isi talash-o-tasawwur mein kho gaya hun mein Tark-e-“Mein” kiye ja aur “Tu” main bus fana ho ja Shan-e-abd paida kar izn-e-Kibriya ho ja Tu hai jab payam Us ka phir payam kya tera Tu hai jab sada Us ki aap be-sada ho ja Admi nahi sunta admi ki baton ko Pekar-e-amal ban kar ghayb ki sada ho ja (Asghar Gondvi & Muhammad Samie) Badalti rehti hai duniya mere khayalon ki Kabhi mila hun kabhi yar se juda hun mein Mujhi ko dekh len ab tere dekhne wale Tu aina hai mera tera aina hun mein (Bedam Shah Warsi) Mein hun afzal sabhi takhleeq ke nazaaron main Khuda nahi hun magar mazhar-e-Khuda hun mein Mazhar-e-Khuda hun mein, Mazhar-e-Khuda hun mein Mazhar-e-Khuda hun mein, Mazhar-e-Khuda hun mein Mein Tamashai nahin Mein Tamashai nahin Mein Tamashai nahin, aap tamasha hun main Mazhar-e-Khuda hun mein, Mazhar-e-Khuda hun mein Mazhar-e-Khuda hun mein, Mazhar-e-Khuda hun mein Charha sooli jo an-al Haq ki sada di mein ne Qum bi izni kaha to khaal khench di mein ne Bandagi ki barhi qeemat hai chukaai mein ne Mein hun khaki hai mehaz khak se nisbat meri Fana hun Tujh mein to phir deed-e-Kibriya hun mein

--Muhammad Samie

Copyright Muhammad Samie, content source youtube.com