[go: up one dir, main page]

100% found this document useful (1 vote)
533 views4 pages

DAY 02 Excercise

The document provides 16 programming problems involving string manipulation in Java. The problems cover a range of tasks including joining strings, reversing strings, comparing strings, modifying case, extracting substrings, converting types, and counting characters. For each problem, sample input and output is provided.

Uploaded by

vishnuselva
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
100% found this document useful (1 vote)
533 views4 pages

DAY 02 Excercise

The document provides 16 programming problems involving string manipulation in Java. The problems cover a range of tasks including joining strings, reversing strings, comparing strings, modifying case, extracting substrings, converting types, and counting characters. For each problem, sample input and output is provided.

Uploaded by

vishnuselva
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
You are on page 1/ 4

String–Exercise

#1 Program
Create a Java program to accept 2 strings and join both the strings, if both the strings are equal then
print “Cannot join the string as they are same” else print the result.

OUTPUT
Given String value 1: ____________
Given String value 2: ____________
___________________

#2 Program
Create a Java program which accepts an input and do the following
1. Display the number of characters in the String
2. If the number of character is greater than 5, then reverse the String
3. If the number of character is less than 5, then display message as “Least value to reverse”
OUTPUT
Given String value: ______________
Length of the String: ________
Reverse value: _____________
#3 Program:
Create a java program to get two input strings and check whether both the string characters are same. If
same print “Strings are same” is not same then print “Strings are not same”

OUTPUT
Given string 1: ______________
Given string 2: ______________
Strings are ____________
#4 Program:
Create a program to accept a string and do the following
a. Convert a string to small letters
b. Convert the sentence to capital letters
c. Convert the string to init-cap

OUTPUT
Given string: ____________
Small letters of string: _____________________
Capital letters of string: _____________________
Init caps of string: _________________________
#5 Program:
Create a Java program to accept 2 Strings
a. In First String change the first occurrence of second string with “XX”
b. In First String change the rest of occurrence of second string with “XXX”
OUTPUT:
Given string 1: ____________
Given string 2: ___________
After First occurrence replace: __________________
After rest of occurrence replace: __________________
String–Exercise

#6 Program:
Create a program to accept 2 String and a position(n) and find the character at the nth place of first
String and replace that character with Second String

OUTPUT:
Given string 1: ____________
Given string 2: ___________
Position: ___________
Before replace: _____________
After replace: ______________

# 7 Program:
Create a program to accept a number with decimal value.
Calculate how many digits before the decimal point and after decimal point

OUTPUT:
Given string 1: ____________
Digits before decimal:___________
Digits after decimal:___________

# 8 Program:
We have 2 student names Ali Al-Ali and Ahmed Al-Ahmed. Design and implement a Java
program that will exchange the last name of the two students in such a way that the new names are
going to be Ali Al-Ahmed and Ahmed Al-Ali.

OUTPUT:
After changing first student : _____________, next student: _______________

# 9 Program:
We have the student name ali al-ali. Desing and implement a Java program that will change the
first letter with the last letter and the new name is going to be ili al-ala.

OUTPUT:
After changing: _______________

# 10 Program:
Create a program to accept a string
a. Print number of words in the string
b. Find the number of character in each word
c. Reverse each word and print

OUTPUT:
Given string 1: ____________
Word count:___________
Character count: word:xxx, word:xxx…..__
Reverse of word: ______, ______ ,______ ….
String–Exercise

# 11 Program:
Create a program to accept a string and insert the following between each character.
a. Insert “=” after number
b. Insert “SP” after space
c. If “#” after the characters
d. If other than character removed all from the string

OUTPUT:
Given string 1: ____________
After replacing =:___________

# 12 Program:
Create a program to accept 5 String as numbers
a. Convert first 4 numbers to float
b. Convert 5th numbers to int
c. Print the sum of the first 4 numbers and average
d. Round the nearest value of 4 numbers and print the sum
e. Add the sum of first 4 values with 5th number and print the result.

OUTPUT:
Numbers 1..5 : ______, ______, ______, ______, ______,
Sum of first 4 numbers:________________
Sum of first 4 rounded numbers:________________
First 4 and last number total: ________________

# 13 Program:
Create a program to accept a string and convert the first character to char and check the input
characters is upper case, lower case, digits.

OUTPUT:
The character is:________________

# 14 Program:
Create a program to accept age in number and print the level (use ternary operator)
If not number then print “Please enter a valid age in number”
else
a. age <=5 baby
b. age >5 and <=10 - print “children
c. age >10 and <=25 - print student
d. age >25 and <=50 - print Young Man
e. If age >50 - old man

OUTPUT:
Age level:________________
String–Exercise

# 15 Program:
Create a program to accept 2 String which contains only numbers. (use ternary operator)
a. Calculate the sum of each digits in String1 and String2 separately
b. Print “String 1 is greater” or “String 2is greater” based on the comparison

OUTPUT:
Which one is greater?________________

# 16 Program:
Program to count the frequency of a given letter in a given string.

OUTPUT:
Given String: _______________
Given Letter: _______________
Frequency of letter: _______________

You might also like