0% found this document useful (0 votes)
6 views3 pages

String Assignment

The document contains a series of Java programming tasks and exercises focused on string manipulation, including methods for finding indices, substrings, and character comparisons. It also includes programs for creating new words from two strings, converting sentences to uppercase, counting specific words, and identifying special and palindrome words. Additionally, there are tasks related to formatting output, reversing words, and performing arithmetic operations on numeric strings.

Uploaded by

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

String Assignment

The document contains a series of Java programming tasks and exercises focused on string manipulation, including methods for finding indices, substrings, and character comparisons. It also includes programs for creating new words from two strings, converting sentences to uppercase, counting specific words, and identifying special and palindrome words. Additionally, there are tasks related to formatting output, reversing words, and performing arithmetic operations on numeric strings.

Uploaded by

somilhenry9
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

String assignment

Write the output of the following:


a) “SUCCESS”.indexOf(‘C’)+”SUCCESS”.lastIndexOf(‘C’)
b) [Link](“Lucknow”.substring(0,4))
c) String s=” Today is Test”;
[Link](s. indexOf(‘T’)+ [Link](‘t’);
[Link]([Link](0,7+ “ “ +”Holiday”);
d) [Link]( “MISSISSIPPI”.indexOf(‘S’)+ “MISSISSIPPI”.lastIndexOf(‘I’)+
“MISSISSIPPI”.length());
e) String s= “Examination”;
int n=[Link]();
[Link] ([Link]([Link](5,n);
[Link] ([Link](2)==[Link](6));

f) Write a statement each to perform the following tasks on a string.


i) Find and display the position of the last space in a string s.
ii) Extract the second last character of a word stored in a variable wrd.
iii) Check if the second character of a string str is in uppercase.

Programs:

1. Define a class two accept two strings of same length and form a new word in such a
way that the first character of the first word followed by first character of the second
word and so on.
Example : input string1 – BALL
input string2 – WORD
OUTPUT : BWAOLRLD
2. Write a program to input a sentence and convert it into upper case and display each
word in separate line.
Example : Input : India is my country
Output :
INDIA
IS
MY
COUNTRY
3. Write a program to input a sentence and convert it into uppercase and count and
display the total number of words starting with a letter ‘A’.
Input: ADVANCEMENT AND APPLICATION OF INFORMATION
TECHNOLOGY ARE EVER CHANGING.
Output : Total number of words starting with ‘A’ =4
4. WAP in java to enter a string print the sentence along with longest and smallest word.
Input: Honesty is the best policy
Output: Longest word: Honesty
Smallest word: is
5. WAP in java to enter a word convert in capital letter and arrange in alphabetical
order.
Input: Java
Output: JAVA
Word after sorting: AAJV
6. WAP to input a word and print in Piglatin form, convert the word in 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 end followed by “AY”.
Input: London Olympics
Output: ONDONLAY OLYMPICSAY
7. WAP to enter a sentence and the count the number of times a particular word occurs
in it. Display the frequency of the search word.
8. Special words are that word which starts and ends with same letter.
Example : EXISTANCE, COMIC, WINDOW etc.
Palindrome words are those which read the same from left to right and vice-versa.
Example : MALAYALAM, MADAM, LEVEL, ROTATOR & COMIC.
All palindrome words are special word, but all special words are not palindrome.
WAP to accept a word, check and print whether the word is palindrome or only
special word.
9. WAP to accept a word and convert into uppercase. Separate vowels and consonants
from the string and print them in two separate strings.
Input : Frequency
Output : vowel word : EUE consonant word : FRQNCY
10. 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 and Republic to
Independence and finally print ““August 15 is celebrated as the Independence Day
of India”
11. Input a string. Print the original string. Also print new string after reversing each
word as its own place.
Input : This IS a Zoo
Output : sihT SI a ooZ.
12. WAP to input a String and find the longest word from the string and print the total
number of vowels present in the longest word.
Input : java programming language
Output:
Longest word: programming
Number of vowels : 3.
13. WAP to input 2 numeric string and an operator ( +, -, *, / , %). Print the
corresponding arithmetic result on the basis of operator.
Input : S1=”46”, S2=”10” and operator = *
Output: Result of 46 10 using * = 4610
14. WAP to input a String. Convert into uppercase. Count the output the number of
double letter sequences that exists in the string.
Input : “ SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE.
Output : 4
15. Write a program in java to accept a word/a string (say “SALMAN”) and display the
pattern.
N N N N N N
A A A A A
L L L L
M M M
A A
S
16 Write a program to enter a string. Convert in uppercase and shift each letter of English
Alphabet one step towards right. Characters other than alphabet remain same. Print
original and new String in two different lines.

Original : ANIMALS ARE KEPT IN ZOO FOR 7 DAYS

New : BOJNBMT BSF LFQU JO APP GPS 7 EBZT

You might also like