0% found this document useful (0 votes)
390 views7 pages

String XII Isc by Prateik Sharma

The document provides 50 problems related to string manipulation in Java. The problems cover a range of tasks including accepting strings from users, analyzing and modifying strings, counting characters, replacing characters, sorting strings, and basic encryption. Example inputs and outputs are provided for many of the problems.

Uploaded by

Prateik Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
390 views7 pages

String XII Isc by Prateik Sharma

The document provides 50 problems related to string manipulation in Java. The problems cover a range of tasks including accepting strings from users, analyzing and modifying strings, counting characters, replacing characters, sorting strings, and basic encryption. Example inputs and outputs are provided for many of the problems.

Uploaded by

Prateik Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

STRING MANIPULATION IN JAVA

1. Write a program in Java to accept a character from the user display whether it is a upper case
character or lower case characters or digit or blank space or special character.
2. Write a program in Java to accept a character from user and convert the uppercase character
to lowercase and display the new character.
3. Write a program in Java to accept a character from user and convert the lower case to upper
case and display the new character.
4. Write a program in Java to accept a string and display each and every character of string in
new line.
5. Write a program in Java to accept a string and display * between each and every character of
string.
6. Write a program in Java to accept a string and display character of string which are present
on even index numbers .
7. Write a program in Java to accept a string and display character of string which are present
on odd index numbers .
8. Write a program in Java to accept a String from the user count and display the number of
upper case character,the number of lower case characters and the number of blank spaces.
9. Write a program in Java to accept a string and display all vowels present in the string.
10. Write a program in Java to accept a string and display * in place of vowels present in the
string.
11. Write a program in Java to accept a string and delete all the vowels present in it.
12. Write a program in java to accept a string and display all UPPERCASE Character present in
the string.
13. Write a program in java to accept a string and display all lowercase Character present in the
string.
14. Write a program in java to accept a string from user and convert the uppercase character
to lowercase and lower case to upper case and display the new string. Example:
INPUT : WelComE TO IMz OUTPUT : wELcOMe to imZ
15. Write a program in Java to accept a string from user and display the new string after
removing all the blank spaces.
e.g : INPUT : My string program OUTPUT : Mystringprogram
16. Write a program in Java to accept a string from user and count the number of times the
given character ‘a’ is present in the string.
17. Write a program in Java to accept a string from user and also accept a character from user
and count the number of times the given character is present in the string.
18. Write a program in Java to accept a string from user and also accept two characters from
user and replace the first character with second character in the string and form a new
string. e.g. INPUT : ABCDABAC Characters A and M OUTPUT : MBCDMBMC
19. Write a program in Java to accept a string and display sum of digits which present in given
string.
SAPMLE INPUT: COM345MTO91QA
SAMPLE OUTPUT: 22

Prateik Sharma 8787274046 , 8299424425 Page 1 of 7


20. Write a program in Java to accept a string and print the reverse form of the string.
21. Write a program in Java to input any string and check it is Palindrome or not. e.g. Madam
Malayalam
22. Write a program in Java that encodes a word into Pig Latin. To translate word into a Pig
Latin word, convert the word into uppercase and then place the first vowel of the original
word as the start of the new word along with the remaining alphabets. The alphabets
present before the vowel being shifted towards the end followed by “AY”.
Sample Input :London
Sample Output : ONDONLAY
23. Write a program to input a string in uppercase and print the frequency of each character.
Example :
INPUT : ApPLe
OUTPUT : CHARACTERS FREQUENCY
A–1
E–2
L–1
P–2

24. Write a program to input a string in uppercase and print the frequency of each character.
Example :
INPUT : ApPLe
OUTPUT : CHARACTERS FREQUENCY
a–1
e– 2
l–1
p–2
25. Write a program to input a string in uppercase and print the frequency of each character.
Example :
INPUT : AapPLeEe
OUTPUT : CHARACTERS FREQUENCY
A–1
a–1
E–1
e–2
L–1
P–1
p–1

Prateik Sharma 8787274046 , 8299424425 Page 2 of 7


26. Write a program in Java to accept a string. Covert the string to Uppercase. Count and
output the number of double letter sequences that exists in the string.
Sample Input: “He grabbed apple ”
OUTPUT: 2
27. Write a program in Java to accept a string from user which includes all punctuation marks
(special characters like “ “ , . ; : ‘ ’ ! ) and display total number of punctuation marks
present in the string.
28. Write a program in Java to accept a string from user and print the total number of words in
the string.
29. Write a program in Java to accept a string from user and display each word present in the
string in new line.
30. Write a program in Java to accept a string from user and replace first character of each
word present in the string by *.
31. Write a program in Java to accept a string from user and capitalise first character of each
word present in the string.
32. Write a program in Java to accept a string from user and capitalise last character of each
word present in the string.
33. Write a program in Java to accept a string and replace each ‘a’ to ‘an’ present in the string.
( It should not be part of the word )
34. Write a program in Java to accept two string of same length and display the new string
after taking one character from first string and second character from second string.
35. Write a program to enter a sentence from the keyboard and count the number of times a
particular word occurs in it. Display the frequency of the search word. Example:
SAMPLE INPUT Enter a sentence: the quick brown fox jumps over the lazy dog.
Enter a word to be searched: the
SAMPLE OUTPUT Searched word occurs. 2 times.
36. Write a program in Java to input any string and find longest word.
SAMPLE INPUT: Shaping our own generation
SAMPLE OUTPUT: longest word is: Shaping and length is: 7
37. Write a program in Java to input any string and find smallest word.
SAMPLE INPUT: Shaping our own generation
SAMPLE OUTPUT: smallest word is: own and length is 3
38. Write a program in Java to accept a name and display the in following form.
SAMPLE INPUT:Mahendra Singh Dhoni
SAMPLE OUTPUT : M.S.D.
39. Write a program in Java to accept a name and display the in following form.
SAMPLE INPUT: Mahendra Singh Dhoni

Prateik Sharma 8787274046 , 8299424425 Page 3 of 7


SAMPLE OUTPUT: M.S. Dhoni
40. Write a program in Java to accept a name and display the in following form.
SAMPLE INPUT: Mahendra Singh Dhoni
SAMPLE OUTPUT: Dhoni M.S.
41. Write a program in Java to accept a name and display the in following form.
SAMPLE INPUT: Mahendra Singh Dhoni
SAMPLE OUTPUT: Dhoni S. Mahendra
42. “January 26 is celebrated as the Republic Day of India”
WAP to change 26 to 15, January to August, Republic to Independence and finally print
“August 15 is celebrated as the Independence Day of India”.
43. Write a program to accept a two word and check whether it is Anagram or not. Example:
INPUT : WOLF FLOW OUTPUT: ANAGRAM
44. Write a program to accept a string and encode the string by replacing each alphabets with
the next fourth alphabet in cyclic order.
Sample Input-"ZEBRA"
Sample Output-"DIFVE"
45. Write a program in Java to enter a String and arrange in alphabetical order.
Sample Input : computer
Sample output cemoprtu
46. Write a program in Java to enter a String and arrange each word in the string in
alphabetical order.
Sample Input : computer very good
Sample output cemoprtu ervy dgoo
47. Write a program in Java to enter a String and second largest word in the string.
48. Write a program in Java to accept a String and display the length of each and every word in
the string.
49. Write a program in Java to accept a string and encode it by increasing the value of each
character by 2 and print the new string.e.g. ABCDGZ output : CDEFJB
50. Write a program in Java to accept a string and encode it by Decreasing the value of each
character by 2 and print the new string.
51. Write a program in Java to accept a string and encode it by Increasing the value of each
character by number given by user and print the new string.
52. Write a program in Java to accept a string and encode it by Decreasing the value of each
character by number given by user and print the new string.
53. Write a program to input a word from the user and remove the duplicate characters present
in it.
54. Caesar cipher is an encryption technique which is implemented as rot13 (‘rotate by 13
places’). It is a simple letter substitution cipher that replaces a letter with the letter 13
places after it in the alphabets, with the other characters remaining unchanged.

Prateik Sharma 8787274046 , 8299424425 Page 4 of 7


Write a program to accept a plain text of length L, where L must be greater than 3 and less than
100.

Encrypt the text if valid as per the Caesar Cipher.

Test your program with the sample data and some random data:

Example 1
INPUT : Hello! How are you?
OUTPUT :
The cipher text is:
Uryyb? Ubj ner lbh?

55. Write a program to accept a sentence which may be terminated by either’.’, ‘?’or’!’ only. The
words may be separated by more than one blank space and are in UPPER CASE.

Perform the following tasks:

(a) Find the number of words beginning and ending with a vowel.

(b) Place the words which begin and end with a vowel at the beginning, followed by the remaining
words as they occur in the sentence.

Test your program with the sample data and some random data:

Example 1

INPUT: ANAMIKA AND SUSAN ARE NEVER GOING TO QUARREL ANYMORE.

OUTPUT: NUMBER OF WORDS BEGINNING AND ENDING WITH A VOWEL= 3

ANAMIKA ARE ANYMORE AND SUSAN NEVER GOING TO QUARREL

55. Accept a paragraph of text consisting of sentences that are terminated by either ‘.’ (full stop),
‘!’ (exclamation mark) or a ‘?’ (question mark). Assume that there can be maximum 10 sentences
in a paragraph. Write a program to arrange the sentences in increasing order of their number of
words.

Example:
INPUT : Please come and attend the party. Hello! How are you?
OUTPUT:
Hello=1

How are you = 3

Prateik Sharma 8787274046 , 8299424425 Page 5 of 7


Please come and attend the party = 6

56. The encryption of alphabets are to be done as follows:

A=1
B=2
C=3
.
.
.
Z = 26
The potential of a word is found by adding the encrypted value of the alphabets.

Example: KITE

Potential = 11 + 9 + 20 + 5 = 45

Accept a sentence which is terminated by either “ . ” , “ ? ” or “ ! ”. Each word of sentence is


separated by single space. Decode the words according to their potential and arrange them in
ascending order.

57. Write a program to accept a sentence which may be terminated by either ‘.’ or ‘?’ only. The
words are to be separated by a single blank space. Print an error message if the input does not
terminate with ‘.’ or ‘?’. You can assume that no word in the sentence exceeds 15 characters, so
that you get a proper formatted output.

Perform the following tasks:


(i) Convert the first letter of each word to uppercase.
(ii) Find the number of vowels and consonants in each word and display them with proper headings
along with the words.

Test your program with the following inputs.

Example 1

INPUT: Intelligence plus character is education.

OUTPUT:
Intelligence Plus Character Is Education

Word Vowels Consonants

Intelligence 5 7

Plus 1 3

Character 3 6

Prateik Sharma 8787274046 , 8299424425 Page 6 of 7


Is 1 1

Education 5 4
58. Write a program to accept a sentence which may be terminated by either ‘.’ ‘?’ or ‘!’ only. Any
other character may be ignored. The words may be separated by more than one blank space and
are in UPPER CASE.

Perform the following tasks:

(a) Accept the sentence and reduce all the extra blank space between two words to
a single blank space.
(b) Accept a word from the user which is part of the sentence along with its
position number and delete the word and display the sentence.
Test your program with the sample data and some random data:

Example 1
INPUT: A MORNING WALK IS A IS BLESSING FOR THE WHOLE DAY.
WORD TO BE DELETED: IS
WORD POSITION IN THE SENTENCE: 6

59. A sentence in the Special Fashion can be printed by taking two integers (not beyond total
number of words in the sentence or less than 1). These integers tell the word number of the
sentence. Replace only those words present at those given integer places by the next character in
a circular fashion according to the English Alphabets. If both the integers are same then replace
only one word. let us consider the following examples:

Sentence: He has good Books.

Input Integers: 2,4

Output Sentence: He ibt good Cpplt.

(i.e. word number 2 and 4 have been replaced by the next characters in a circular fashion)

60. Write a program to assign a full path and file name as given below. Using library functions,
extract and output the file path, file name and file extension separately as shown.

Input: C:Users\admin\Pictures\flowers.jpg
Output:
Path: C:Users\admin\Pictures
File name: flower
Extension: jpg

Prateik Sharma 8787274046 , 8299424425 Page 7 of 7

You might also like