Java String Manipulation Programs


Java / Friday, August 17th, 2018
(Last Updated On: August 17, 2018)

Java String Manipulation

Today I am going to discuss about some java string manipulation programs. The programs that I am discussing are of basic to intermediary levels. I assume that you have some knowledge about java string class and its methods, if not you can learn it from by post on Java string class.

In the first program I will show working of some of the java string class methods. Let’s try

 Program 01

Output:

The upper case of Sourav is = SOURAV
The upper case of computer is = COMPUTER
The lower case of COMPUTER is = computer
The value of Sourav
After replacing m with n of computer we get conputer
Lupta
The string after removing blank spaces = easy understanding
The equal string = false
The equal string = true
The length of rajib Kumar Saha = 17
The charecter at 5th position of computer = u
The substring from the 6th index: nderstanding
The substring out of 9, leaving first 4 characters: unde
The first occurence of the character ‘a’: 1
The index of ‘a’ from 5th character: 9
The compare string: -32
The compare without case string: true

Note: To take input from the user I am using Scanner class. If you don’t know how the Scanner class works, then follow the link.

 Program 02

Write a program to display the given pattern.
R
RA
RAJ
RAJI
RAJIB

Output:

Enter your word to show the pattern:
RAJIB

R
RA
RAJ
RAJI
RAJIB

 Program 03

Write a program to display the given pattern.
Pattern2

 

 

Output:

Enter your word to show the pattern: RAJIB
Pattern2

 

 

 

 Program 04

Write a program to display the given pattern.
LIVEDU
IVEDUL
VEDULI
EDULIV
DULIVE
ULIVED

Output:

Enter your word to show the pattern: LIVEDU
LIVEDU
IVEDUL
VEDULI
EDULIV
DULIVE
ULIVED

 Program 05

Write a program to accept a string. Count and display the number of vowels present in the String.

Output:

Enter any string: I love Java
The number of vowel present in I love Java is 5

 Program 06

Write a program to accept a string in lower case and replace ‘e’ with ‘*’ in the given string. Display the new string.

Output:

Enter a string: computer science
The new String is comput*r sci*nc*

 Program 07

Write a program to accept a string and change the case of each letter of the string. Display the new string.

Output:

Enter your string: String Manipulation Programs in Java
The string before converting the case of each alphabet: String Manipulation Programs in Java
The string after converting the case of each alphabet: sTRING mANIPULATION pROGRAMS IN jAVA

 Program 08

Write a program to accept a name and display the initials along with the surname.

Output:

Enter full name: Rajib Kumar Saha
You have entered the name: Rajib Kumar Saha
Name as initial with surname: R.K. Saha

 Program 09

Write a program in Java to accept a sentence and a word that present in the sentence. Find and print the frequency of the given word in the sentence.

Output:

Enter a string: the quick brown fox jumps over the lazy dog
Enter a word to be searched in the string: the
Frequency of searched word present in the string: 2

 Program 10

Write a program in Java to accept a word and display the same in Pig Latin from

Pig Latin: A word is said to be in Pig Latin form when it is obtained by forming a new word by placing the four vowel of the original word at the start of the new word along with the letters following it. The letters present before the first vowel are shifted to the end of the new word, followed by ‘ay’.

Output:

Enter the string: trouble
The Pig Latin form of the given string: oubletray

*  Try to understand yourself….if any doubt comes write comment then I will solve your doubt.

** If you find problem solving any string related program, comment it or send it to me, I will love to help you.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *