Self-Practice_Java Strings - Questions
Self-Practice_Java Strings - Questions
Practice No. : 3b
Topic : Strings
Date : 15.02.2025
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