File tree Expand file tree Collapse file tree 2 files changed +72
-0
lines changed Expand file tree Collapse file tree 2 files changed +72
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * PROGRAM : To find the most repeated word in a string.
3
+ * FILE : RepeatWord.java
4
+ * CREATED BY: Santosh Hembram
5
+ * DATED : 14-10-20
6
+ */
7
+ import java .util .*;
8
+ class RepeatWord {
9
+
10
+ public static void mostRepeatWord (String str ) {
11
+
12
+ for (int i =0 ; i <str .length ; i ++) {
13
+
14
+ System .out .println (str [i ]);
15
+
16
+ }
17
+
18
+ }
19
+
20
+ public static void main (String [] args ) {
21
+
22
+ String str ;
23
+ System .out .print ("Enter a string: " );
24
+ Scanner sc = new Scanner (System .in );
25
+ str = sc .nextLine ();
26
+
27
+ mostRepeatWord (str );
28
+ }
29
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * PROGRAM : To swap two string variables without using third variable
3
+ * FILE : StringSwap.java
4
+ * CREATED BY: Santosh Hembram
5
+ * DATED : 14-10-20
6
+ */
7
+
8
+ import java .util .*;
9
+ class StringSwap {
10
+
11
+ public static void swap (String str1 , String str2 ) {
12
+
13
+ str1 = str1 + str2 ;
14
+
15
+ str2 = str1 .substring ( 0 ,str1 .length () - str2 .length () );
16
+
17
+ str1 = str1 .substring (str2 .length () );
18
+
19
+ System .out .println ("After swapping the string: " );
20
+ System .out .println ("string 1: " +str1 );
21
+ System .out .println ("string 2: " +str2 );
22
+
23
+
24
+ }
25
+
26
+ public static void main (String [] args ) {
27
+
28
+ String str1 ,str2 ;
29
+
30
+ System .out .print ("Enter the first string: " );
31
+ Scanner sc = new Scanner (System .in );
32
+ str1 = sc .nextLine ();
33
+
34
+ System .out .print ("Enter the second string: " );
35
+ str2 = sc .nextLine ();
36
+
37
+ System .out .println ("Display the string before swapping: " );
38
+ System .out .println ("string 1: " +str1 );
39
+ System .out .println ("string 2: " +str2 );
40
+
41
+ swap (str1 ,str2 );
42
+ }
43
+ }
You can’t perform that action at this time.
0 commit comments