Sunteți pe pagina 1din 7

8 : String Manipulation in Java

1. Write a program to accept two different characters and display the sum and difference of their values.

Sample Input :
A
d
Sample Output :
The sum of ASCII values 165
The difference of ASCll value 35

2 Write a program to accept a character. If it is a letter, then display the case (i.e. lower or upper case), otherwise check whether it is a digit or a special
character.

Sample Input: p
Sample output: p is a letter,
p is in lower case.

3. Write a program in Java to accept a word/a string and display the new string after removing all the vowels present in it.

Sample input COMPUTER APPLICATIONS


Sample output: CMPTR PPLCTONS

4. Write a program in Java to accept a word/a string. Count all the letters excluding the vowels present in the word/string and display the result.

Sample Input: Happy New Year


Sample Output : No. of letters excluding vowels 8

5. Write a program in Java to accept a name(Containing three words) and Display only the initials (i.e. first letter of each word.)

Sample Input LAL KRISHNA ADVANI


Sample output LKA

6 Write a program in Java to accept a name containing three words and display the surname first, followed by the first and middle names
Sample Input : MOHANDAS KARAMCHAND GANDHI
Sample Ouput : GANDHI MOHANDAS KARAMOHAND
7. Write a program in Java to accept a sentence and find the frequency of a given letter.

Sample Input WE ARE LIVING IN COMPUTER WORLD


Enter a letter whose frequency is to be checked (Say: E)
Sample Output The frequency of 'E' is 3.

8. Write a program in Java to enter a string/sentence and display the longest word and the length of the longest word present in the String.

Sample Input : "TATA FOOTBALL ACADEMY WILL PLAY AGAINST MOHAN BAGAN"
Sample Output : The longest word FOOTTBALL : The length of the word : 8

9. Write a program in Java to accept String in upper case and find the frequency of each vowel present in the String.

Sample Input : "RAIN WATER HARVESTING ORGANISED BY JUSCO"


Sample Output :
Frequency of 'A' : 4
Frequency of 'E' : 3
Frequency of 'I' : 3
Frequency of 'O' : 2
Frequency of 'U' : 1

10. Write a program in Java to accept a String as :


"IF IT RAINS, YOU WILL NOT GO TO PLAY"
Convert all letters of the words other than the first letters to lower case so as to obtain the following output

Sample Output :
If It Rains, You Will Not Go To Play

11. Write a program in Java to accept a word and display the ASCII of each character

Sample input :
SKY

Sample output :
ASCII of S : 83
ASCII of K : 75
ASCII of Y : 89
12. Write a program in Java a String in upper case and replace all the vowels with Asterisk (*) present in the String.

Sample Input : "TATA STEEL IS IN JAMSHEDPUR"


Sample Output : "T*T* ST**L *S *N J*MSH*DP*R"

13. Write a program to input a string. Print the new string after converting every alternate letter to uppercase and the next immediate letter to lowercase.
The special characters remain the same..

Input : Delhi Public School


Output : DeLhl pUbLiC sChOoL

14. Write a program to accept a string. Modify the string by adding "hot' at the beginning of the word. If the string already contains hot, then the string
remains unchanged.
Print the modified string and the message accordingly.

Sample Input: CAKE


Sample output: HOTCAKE

Sample Input: HOTLINE


Sample output: No change in the string

15. Write a program in Java to enter a string and frame a word by joining all the first characters of each word. Display the new word.

Sample Input : Vital Information Resource Under Seize


Sample output : VIRUS

16. Write a program in Java to enter a string and display all the palindrome words present in the String.

Sample Input : MOM AND DAD ARE NOT AT HOME


Sample output :
MOM
DAD

17. Write a program to accept a string. Display the string in reverse order.

Sample Input :
Computer is Fun
Sample Output :
Fun is Computer

18. Write a program to input a string and print the character which occurs the maximum number of times within the String.

Sample Input : James Gosling developed Java


Sample output : The character with maximum number of times: e

19. Write a program to input a string and print the word containing the maximum number of vowels.

Sample Input : HAPPY NEW YEAR


Sample Output : The word with maximum number of vowels: YEAR

20. Consider the string as:


Blue bottle is in Blue bag lying on Blue carpet

Write a program to accept a sample string and replace the word Blue with Red, The new string is displayed as:
Red bottle is in Red bag lying on Red carpet

21. A computer typist has the habit of deleting the middle name .'Kumar', while entering the names containing three words. Write a program to enter a
name with three words and display the new name after deleting the middle name 'Kumar'.

Sample Input : Ashish Kumar Nehra


Sample Output : Ashish Nehra

22 Write a program to accept a word and convert it into lower case, if it is in upper case. Display the new word by replacing only the vowels with the letter
following it.

Sample Input : computer


Sample Output : cpmpvtfr

23. A string is said to be 'Unique' if none of the letters 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
24. Write a program to input a sentence in uppercase. Create a new sentence by replacing each vowel with the next (ie. A with E, U with A) and the other
characters remain the same. Display the new sentence accordingly.

Sample Input : WE CELEBRATE 26 JANUARY AS REPUBLIC DAY


Sample Output : WI CILIBRETI 26 JENAERY ES RIPABLOC DEY

25. A "Happy Word' is defined as:


Take a word and calculate the word's value based on position of the letters in English alphabet. On the basis of word's value, find the sum of the squares of
its digits. Repeat the process with the resultant number until the number equals 1 (one). If the number ends with 1 then it is called a 'Happy Word'. Write
a program to input a word and check whether it a 'Happy Word' or not. The program displays a message accordingly.

Sample Input:
VAT
Place value of V=22, A=1, T=20
[Hint: A=1, B=2,..........Z=26]

Solution: 22120 = 2^2+2^2+1^2+2^2+0^2 = 13 = 1^2 + 3^2 = 10 = 1^2+0^2 = 1


Sample Output : A Happy Word

26. A non-palindrome word can be made a palindrome word just by adding the reverse of the word to the original word. Write a program to accept a non-
palindrome word and display the new word after making it a palindrome.

Sample Input :
ICSE
Sample Output :
The new word making it palindrome as:
ICSEESCI

27. Write a program to input a string. Count and display the frequency of each letter in the order in which it is present in the String.

Sample Input : DADDY'S CODE


Sample Output :
D:3
A:1
Y:1
S:1
C:1
O:1
D:1
E:1

28. Write a program to accept a string. Convert the string to upper case. Count and output the number of double letter sequences that exist in the string.

Sample Input : "SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE"
Sample output : 4

29. Special words are those words which start and end with the same letter.
Example: EXISTENCE, COMIC, WINDOW
Palindrome words are those words which read the same from left to right and vice
Example: MALYALAM, MADAM, LEVEL, ROTATOR, CIVIC
All palindromes are special words but all special words are not palindromes.
Write a program to accept a word. Print and display whether the word is a palindrome or only a special word.

30. Write a program to input a string. Convert the string to upper case. Count and print the words which have at least a pair of consecutive letters.

Sample Input : MODEM IS AN ELECTRONIC DEVICE


Sample Output :
MODEM
DEVICE
Number of words containing consecutive letters : 2

31. Write a program to accept a word (say,BLUEJ) and display the pattern:
(a) (b) (c)
BLUEJ J BLUEJ
BLUE EE LUEJ
BLU UUU UEJ
BL LLLL EJ
B BBBBB J

32. Write a program to display the pattern :


(a) (b) (c) (d) (e) (f)
ABCDE A ABCDE ABCDE EDCBA A
BCDE BC ABCDA BCDE EDCB AB
CDE DEF ABCAB CDE EDC ABC
DE GHIJ ABABC DE ED ABCD
E KLMNO AABCD E E ABCDE
33. Write a program to generate a triangle or an inverted triangle till n terms based upon the User's choice of the triangle to be displayed.
Example 1 : Example 2 :
Input : Type 1 for a triangle and Type 2 for an inverted triangle Input : Type 1 for a triangle and Type 2 for an inverted triangle
Enter Choice : 1 Enter Choice : 2
Enter No. of Lines : 5 Enter No. of Lines : 5
Sample Output : Sample Output :
***** ABCDE
**** ABCD
*** ABC
** AB
* A

34. Write a program to generate a triangle or an inverted triangle based upon User's Choice.
Example 2 :
Example 1 :
Input : Type 1 for a triangle and Type 2 for an inverted triangle
Input : Type 1 for a triangle and Type 2 for an inverted triangle
Enter Choice : 2
Enter Choice : 1
Enter a Word : BLUEJ
Enter a Word : BLUEJ
Sample Output :
Sample Output :
B L U E J
B
B L U E
L L
B L U
U U U
B L
E E E E
B
J J J J J

35. Using the switch statement, write a menu driven program for the following :
a. To Print the Floyd's Triangle :
b. To display the following pattern :
1
I
23
IC
456
ICS
7 8 9 10
ICSE
11 12 13 14 15
For an incorrect option, an appropriate error message should be displayed.
https://daddyscode.weebly.com/q-x--8--icse.html

S-ar putea să vă placă și