4
4
5
5
/*
6
6
* Swap Two Strings without using third variable
7
+ * ---------------------------------------------
7
8
* Say String1 is : good
8
9
* Say String2 is : bad
9
10
* The output should print string1 is bad and string2 is good
10
11
*
11
12
*/
12
13
13
14
public class SwapTwoStrings {
14
-
15
15
public static void main (String [] args ) {
16
16
Scanner scanner = new Scanner (System .in );
17
17
System .out .println ("Enter the String 1 : " );
@@ -23,7 +23,7 @@ public static void main(String[] args) {
23
23
str2 = str1 .substring (0 ,str1 .length ()-str2 .length ());
24
24
str1 = str1 .substring (str2 .length ());
25
25
26
- System .out .println ("After swapping-- " );
26
+ System .out .println ("After swapping :: " );
27
27
System .out .println ("String 1 is : " +str1 );
28
28
System .out .println ("String 2 is : " +str2 );
29
29
scanner .close ();
@@ -33,13 +33,13 @@ public static void main(String[] args) {
33
33
OUTPUT
34
34
Enter the String 1 : good
35
35
Enter the String 2 : bad
36
- After swapping--
36
+ After swapping::
37
37
String 1 is : bad
38
38
String 2 is : good
39
39
40
40
Enter the String 1 : hello
41
41
Enter the String 2 : world
42
- After swapping--
42
+ After swapping::
43
43
String 1 is : world
44
44
String 2 is : hello
45
45
*/
0 commit comments