0% found this document useful (0 votes)
2 views

Self-Practice_Java Strings - Questions

The document outlines a self-practice exercise for SDE readiness training focused on string manipulation problems. It includes various tasks such as extracting characters, formatting strings, and summing digits from a given string. Each problem is categorized as 'Easy' and provides sample input and output for clarity.

Uploaded by

2k22cse081
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)
2 views

Self-Practice_Java Strings - Questions

The document outlines a self-practice exercise for SDE readiness training focused on string manipulation problems. It includes various tasks such as extracting characters, formatting strings, and summing digits from a given string. Each problem is categorized as 'Easy' and provides sample input and output for clarity.

Uploaded by

2k22cse081
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
You are on page 1/ 2

SELF PRACTICE

SDE Readiness Training

Practice No. : 3b

Topic : Strings

Date : 15.02.2025

Solve the following problems

Q.
Question Detail Level
No.

Given a string, return the string made of its first two chars, so the
String "Hello" yields "He". If the string is shorter than length 2, return
whatever there is, so "X" yields "X", and the empty string "" yields the
empty string "".
1 Easy
Sample Input & Output
("Hello") →"He"
("abcdefg") →"ab"
("ab") →"ab"
Given 2 strings, a and b, return a string of the form short+long+short,
with the shorter string on the outside and the longer string on the
inside. The strings will not be the same length, but they may be empty
(length 0)
2 Easy
Sample Input & Output
(“Hello", "hi") ->"hiHellohi"
("hi", "Hello") ->"hiHellohi"
("aaa", "b") -> "baaab"
Given a string of any length, return a new string where the last 2
chars, if present, are swapped, so "coding" yields "codign
Sample Input & Output
3 Easy
("coding") →"codign"
("cat") → "cta"
("ab") → "ba"
A string S is passed as the input. S can contain alphabets, numbers
and special characters. The program must print only the alphabets in
4 S. Easy
Input:
abcd_5ef8!xyz

Sometimes later becomes never. DO IT NOW!


1
SELF PRACTICE
SDE Readiness Training
Output:
abcdefxyz

Given a string, return a string length 2 made of its first 2 character. If


the string length is less than 2, use '@' for the missing chars.
Sample Input & Output
5 Easy
("hello") → "he"
("hi") → "hi"
("h") → "h@"
Write a Java program to create a new string repeating every character Easy
twice of a given string
6 Sample Input & Output
welcome
wweellccoommee
Write a Java program to return the sum of the digits present in the Easy
given string. If there is no digits the sum return is 0.

7 Sample Input & Output:


ab5c2d4ef12s
14

Sometimes later becomes never. DO IT NOW!


2

You might also like