Java String Programs
Java String Programs
1. Write a Java program to accept a word or a string and display a new string after
removing all vowels.
Sample Input: COMPUTER APPLICATIONS
Sample Output: CMPTR PPLCTNS
2. Write a Java program to enter a string/sentence and display the longest word along
with its length.
Sample Input: "TATA FOOTBALL ACADEMY WILL PLAY AGAINST MOHAN BAGAN"
Sample Output: The longest word: FOOTBALL, The length of the word: 8
3. Write a Java program to accept a string in uppercase and replace all vowels with an
asterisk ().
Sample Input: "TATA STEEL IS IN JAMSHEDPUR"
Sample Output: TT* ST**L S N JMSHDP*R
4. Write a Java program to enter a sentence, extract the first letter of each word, and
form a new word.
Sample Input: Vital Information Resource Under Seize
Sample Output: VIRUS
5. Write a Java program to enter a sentence and display only the words that are
palindromes.
Sample Input: MOM AND DAD ARE NOT AT HOME
Sample Output: MOM, DAD
6. Write a Java program to reverse the order of words in a given sentence.
Sample Input: Computer is Fun
Sample Output: Fun is Computer
7. Write a Java program to input a sentence and display the word containing the
maximum number of vowels.
Sample Input: HAPPY NEW YEAR
Sample Output: The word with maximum vowels: YEAR
8. Write a Java program to accept a word, convert it to lowercase (if in uppercase), and
replace only vowels with their next letter.
Sample Input: COMPUTER
Sample Output: CPMPVTFR
9. Write a Java program to input a sentence, convert it to uppercase, and count words
starting with the letter 'A'.
Sample Input: advancement and application of information technology are ever
changing
Sample Output: ADVANCEMENT AND APPLICATION OF INFORMATION
TECHNOLOGY ARE EVER CHANGING
Total words starting with 'A': 4
10. Write a Java program to input a sentence, convert it to uppercase, and display each
word separately.
Sample Input: India is my country
Sample Output:
INDIA
IS
MY
COUNTRY
11. Write a Java program to accept two strings of the same length and form a new word
by interleaving their characters.
Sample Input: BALL, WORD
Sample Output: BWAOLRLD
12. Write a Java program to accept a string, convert it to uppercase, and count double-
letter sequences.
Sample Input: "SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE"
Sample Output: 4
13. Write a Java program to check whether a given word is a palindrome, a special word
(starts and ends with the same letter), or neither.
Example Special Words: EXISTENCE, COMIC, WINDOW
Example Palindromes: MALAYALAM, MADAM, LEVEL, ROTATOR, CIVIC
14. Write a Java program to input a sentence, convert it to uppercase, and display words
containing at least one pair of consecutive letters.
Sample Input: MODEM IS AN ELECTRONIC DEVICE
Sample Output: MODEM, DEVICE
Total words with consecutive letters: 2
15. Write a Java program to accept a word and display patterns:
(a) BLUEJ → BLUE → BLU → BL → B
(b) J → EE → UUU → LLLL → BBBBB
(c) BLUEJ → LUEJ → UEJ → EJ
16. Write a Java program to generate a triangle or an inverted triangle based on user
choice.
Example 1:
Input: Type 1 for a triangle, Type 2 for an inverted triangle
Choice: 1
Word: BLUEJ
Output:
B
LL
UUU
EEEE
JJJJJ
Example 2:
Choice: 2
Word: BLUEJ
Output:
BLUEJ
BLUE
BLU
BL
B
17. Write a menu-driven Java program using a switch statement:
(a) Print Floyd's Triangle:
Example Output:
1
23
456
7 8 9 10
11 12 13 14 15
(b) Display the pattern:
I
IC
ICS
ICSE
For invalid choices, display an error message.
18. Define a class to accept ten characters in an array and perform a linear search for a
given character.
If found, display the character and its index.
If not found, display "No such character is available in the array".
19. Write a Java program to store names of ten countries and their capitals in separate
arrays. Display only the countries that start with a vowel along with their capitals.
Example Output:
Countries Name | Capital
XXXX | XXXX
XXXX | XXXX
20. Write a Java program to store 20 names and telephone numbers in two separate
arrays. Sort names alphabetically using the selection sort technique and display them
along with corresponding phone numbers.
21. Write a Java program to accept 10 names in an array and display names that start
with a user-input letter.
Sample Input:
Aman Shahi
Akash Gupta
Suman Mishra
Sample Output (if input letter is 'A'):
Aman Shahi
Akash Gupta