0% found this document useful (0 votes)
18 views4 pages

String Manipulation Programming Tasks

Uploaded by

rautapurnamashi
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)
18 views4 pages

String Manipulation Programming Tasks

Uploaded by

rautapurnamashi
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

String Based Question

1) Write a program to accept a word and convert it into lowercase if it is in


uppercase, and display the new word by replacing only the vowels with the
character following it.
Example:
Sample Input: computer
Sample Output: cpmpvtfr
2) Write a program to accept a string. Convert it to uppercase. Count and
output the number of double letter sentences that exist in the string.
Sample Input : “SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE”
Sample output: 4
3) Write a program that encodes a word into Piglatin. To translate word into a
piglatin 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 : 1) London Sample Output : ONDONLAY
Sample Input : 2) Olympics Sample Output : OLYMPICSAY
4) Write a program to input a String. Count and display the frequency of each
alphabet in an order, which is present in the String.
Sample Input : “ COMPUTER APPLICATION”
Sample Output:
Character Frequency Character Frequency
A 2 O 2
C 2 P 3
E 1 R 1
I 2 S 1
L 1 T 2
M 1 U 1
N 1

5) Write a program to input a sentence and print the number of characters


found in the longest word of the given sentence.
Sample Input: “India is my country”
Sample Output: The longest word is country is country
Number of characters in the longest word is 7
6) Write a program to input a string and print out the text with the upper case
and lower case letters reversed, but all other characters should remain the
same as before.
Example: Input: WelComE TO School
Output: wELcOMe to sCHOOL
7) Write a program to accept a String and display only those characters which
are consecutives.
Sample Input: “UNDERSTANDING COMPUTER APPLICATION”
Sample Output: D, E
R, S
S, T are consecutive characters.
8) Write a program to accept a string in lower case. Convert the first character
of each word of the string in upper case and display the new string.
Sample Input: india got independence in nineteen forty seven
Sample Output: India Got Independence In Nineteen Forty Seven
9) Write a using a function called Count() to accept a String form the user.
Count and display the number of uppercase characters, the number of
lowercase characters and the number of vowels as per the User’s choice
using Switch case:
i) To count the uppercase characters
ii) To count the lowercase characters
iii) To count the number of vowels

10) Write a program in Java to enter a String. Print the String in an alphabetical
order of its alphabets.
Sample Input: “computer”
Sample Output: “ cemoprtu”
11) Write a program to generate a pattern of a word in the form of a triangle or
in the form of an inverted triangle depending upon User’s choice.
Sample Input : Enter a word as a Token: WATER
Enter your choice: 1 Enter your choice:2
Sample Output: W WATER
WA WATE
WAT WAT
WATE WA
WATER W
12) Write a program to accept a String from the user and replace the word
“big” with the “hot”. Display the new String after replacing “big” with “hot”.
Sample Input: “The big bottle in the big water bag.”
Sample Output: “ The hot bottle in the hot water bag.”
13) Consider the following statement:
“ January 26 is celebrated as the Republic Day of India”
Write a program to change 26 to 15, January to August, Republic to
Independence and finally print,
“August 15 is celebrated as the Independence Day of India”
14) Write a program to input a sentence. Count and print the number of words
which are palindrome.
Sample Input : “ MADAM IS MALAYALAM”
Sample Output: Number of palindrome words = 2

16) Write a program to accept a name containing three words ( First name,
Middle name, Surname). Display the name having surname first followed by First
name and middle name.

Sample Input: Madan Lal Khurana

Sample Output: Khurana Madan Lal

17) Write a program in Java to accept string and count the words ( containing at
least two alphabets) which begin with a vowel ( upper or lower case)

Sample Input : BSNL launches One India Plan to connect people.

Sample Output: No. of words begin with a vowel: 2


18) Write a program to accept a string and display the new string after removing
all the vowels from the string.

Sample Input: “Computer Applications with BlueJ”

Sample Output: “Cmptr pplctns wth blJ”

19) A string is said to be “Unique”, if none of the alphabets present in the string
are repeated. Write a program to accept a string and check whether the string is
Unique or not. The program displays a message accordingly.

Sample Input: “COMPUTER”

Sample Output: Unique String.

20) Write a program to generate a pattern of a string entered by the user based
upon User’s choice.

Sample Input: “INDIA WINS CRICKET WORLD CUP 2011”

Enter your choice: 1 Enter your choice: 2

Sample Output: 1

I A

W S

C T

W D

C P

Common questions

Powered by AI

To sort the characters in a string alphabetically in Java: 1) Convert the string to a character array. 2) Utilize Java's `Arrays.sort()` method to sort the array. 3) Convert the sorted array back into a string. This transformed string will have its characters in alphabetical order, such as converting 'computer' to 'cemoprtu' .

To check if a string is 'unique', meaning it contains no repeated alphabets: 1) Initialize a set to keep track of encountered characters. 2) Iteratively examine each character in the string. 3) If a character has been seen before (present in the set), the string is not unique. 4) If no characters repeat, the string is unique. For example, with 'COMPUTER', which has no repeating letters, the output is 'Unique String' .

To transform a sentence so that the first character of each word is uppercase: Split the sentence into words, either using space as a delimiter or regular expressions to match word boundaries. Capitalize the first character of each word while keeping the rest in lowercase. Finally, join the words together to form the modified sentence. For example, 'india got independence in nineteen forty seven' becomes 'India Got Independence In Nineteen Forty Seven' .

To generate a word pattern in the form of a triangle or inverted triangle: 1) Accept a word from the user. 2) Depending on user choice, decide the shape of the pattern. 3) For a triangle, print increasing substrings from the start; for an inverted triangle, print from the full word length down to one character. Considerations include ensuring even character spacing for readability and handling uppercase transformation as needed. Example: For 'WATER' as an input word, a resulting pattern might be: 'W', 'WA', 'WAT', 'WATER', followed by its reverse for an inverted triangle .

To determine the frequency of each alphabet in a string: 1) Initialize a hash map or dictionary to store character frequencies. 2) Traverse the string, converting characters to uppercase or lowercase as needed. 3) For each alphabetic character, update its count in the hash map. 4) Finally, print each alphabet and its frequency in the order of their appearance. For example, for input 'COMPUTER APPLICATION', the output is 'A 2, O 2, C 2, P 3, E 1, R 1, I 1, L 1, T 2, M 1, U 1, N 1' .

To count palindrome words in a sentence, follow these steps: 1) Split the sentence into individual words. 2) For each word, check if it reads the same forwards and backwards. 3) Increment a counter for each word that is a palindrome. 4) Output this count. For instance, in the sentence 'MADAM IS MALAYALAM', both 'MADAM' and 'MALAYALAM' are palindromes, resulting in a count of 2 .

To replace specific words in a sentence: 1) Use a language function available for string replacement, such as `replace()` in Python. 2) Identify the target word(s) to replace and the replacement word. 3) Apply the replacement function across the entire string. For example, replacing 'big' with 'hot' in 'The big bottle in the big water bag.' results in 'The hot bottle in the hot water bag.' .

To convert uppercase letters to lowercase and lowercase to uppercase while keeping non-alphabetic characters unchanged: Traverse through each character in the string. If a character is uppercase, convert it to lowercase, and if it is lowercase, convert it to uppercase. Non-alphabetic characters should be left unchanged. This operation can often be achieved using functions like `swapcase()` in Python .

To convert a word into Piglatin: 1) Convert the word to uppercase. 2) Identify the first vowel in the word. 3) Begin the Piglatin word with this vowel, followed by the rest of the word. 4) Move all characters preceding the vowel to the end, and append 'AY' to form the new word. For example, 'London' becomes 'ONDONLAY' .

To count double letter pairs in a sentence: 1) Convert the sentence to a consistent case, such as uppercase. 2) Traverse the string character by character, checking pairs. 3) For each character, compare with the following one; if they match, it's a double letter pair. 4) Keep a running count of such pairs. For example, in 'SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE', there are 4 double letter pairs: 'EE', 'TT', 'BB', 'PP' .

You might also like