Skip to content

Commit bc0ae2c

Browse files
authored
Add files via upload
1 parent 86880e3 commit bc0ae2c

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

Assignment-10/RepeatWord.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

Assignment-10/StringSwap.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy