STRINGS PROGRAMS
1.Reveres a String?
2.Reverse even words in a particular Sentence.
3.Find 5 mistakes of the following code.
package com.cjss.programming-interviews;
public class String programs {
static void main (String[10] args)
{
String s="abc";
System.out.println(s);
}
}
4.Write a program to check given String is pallindrome or not not by using reverse().
5.Write a program to check and print how many vowels in it.
6.Reverse a word in a String without using inbuilt function.
7.Missing word in a String.
1
STRINGS PROGRAMS
8.Write a program to count number of words in a String
9.Reverse a string without using inbuilt functions.
10.Write a program to print alphabets in a given String.
11.Write a program to print duplicate characters in a given String.
12.Write a program to check whether the given two words are anagram or not.
silent,listen - anagram
listen,enlists -not an anagram.
13.Remove the numbers from the string.
14.Identify the longest word in the Sentence.
input:spacy's named entirely recognition has been trained On the on
output:recognition.
15.write a program given number is convert to words
Ex 420 fourtwozero
16.Write a program to reverse a string.
17.Write a program to check whether the string is pallindrome or not.
2
STRINGS PROGRAMS
18.Reserse the string without using the string function.
19.class Output{
public static void main(String[] args)
{
area obj = new area();
obj.area(5,6);
System.out.println(obj.length+" "+obj.width);
}
}
a)00 b)56 c)65 d)56
20.Which of the following are incorrect form of StringBuffer class Constructor?
a)StringBuffer()
b)StringBuffer(int size)
c)StringBuffer(String str)
d)StringBuffer(int size,String str)
21.Which method is used in thread class to starts the execution of
thread jvm calls the run() on the thread?
a)public void start()
b)public void stop()
c)public void run()
3
STRINGS PROGRAMS
d)public void suspend()
22.In DriverManager class which method is used to establish the connection
with the specified in?
a)public static void registerDriver(Driver driver)
b)public static void deregisterDriver(Driver driver)
c)public static Connection getConnection(String )
d)public static Connection getConnection(String ,StringuserName,String password)
1.What will be the o/p?
public class Test{
public static void main (String[] args){
String x="abc";
String y="abc";
x.concat(y);
System.out.print(x);
}
}
a)null
b)abc
c)abcabc
23.Select all valid methods of String class?
a) trim()
b)intern()
4
STRINGS PROGRAMS
c)toLower()
d)split()
24.String implementation follows which of the below design pattern?
a)Flyweight Design Pattern
b)None of these
c)Singleton Pattern
d)Factory Pattern
25.What will be the o/p?
String s1="abs";
String s2= new String("abc");
System.out.print(s1==s2);
System.out.println(s1==s2.intern());
a)false false
b)true false
c)true true
d)false true
26.What will be the o/p?
String s="Java String Quiz";
System.out.println(s.subString(5,3));
a)Runtime Exception StringIndexOutOfBoundsException
b)Runtime Exception IndexOutOfBoundsException
5
STRINGS PROGRAMS
c)Compile time errr
prints"str"
27.Which of the following statements are true for StringBuffer and StringBuilder?
a)StringBuilder is not thread-safe
b)StringBuffer is thread safe because its methods are synchronized
c)StringBuffer and StringBuilder are immutable
d)StringBuilder was introduced in java 1.4
class String_class
{
public static void main(String[] args)
{
String obj ="Hello";
String obj1="World";
String obj2=obj;
obj2="World";
System.out.println(obj+" "+obj2);
}
}
28.W.A.P to print number of characters ina vowels and string
29.W.A.P to print number of vowels in a given string.
6
STRINGS PROGRAMS
30.Write a program to print number of words in string.
31.W.A.P for duplicate String
32.W.A.P for vowels count in a given String.
33.Strings and string buffer.
W.A.P to print frequency of each character in a given string when count is a primary
number.
34.Input :aaaaBBBcdddd
Output:B-3,c-1
35.Input : a3b2c4
Output:aaabbcccc
36.Input:ak2b3r
output:akkbbbr
37.Input:aaaBBcd
output:a-3,B-2,c-1,d-1
38.Input:HelloWorld
Output:Helowrd
7
STRINGS PROGRAMS
39.Input:abcde
Output:badce
40.Count the vowels
41.Number of words in the strings.
42.public class Test
{
void display(Test t){
System.out.println("Test");
}
void display(String str)
{
System.out.println("String");
}
public static void main(String[] args)
{
new Test().display(null);
}
}
43.public class Metti{
8
STRINGS PROGRAMS
public static void main(String[] args)
{
String s="This is a line";
String[] tokens =s.split(" ");
System.out.println(tokens.length);
}
}
44.Public static void main(String[] args)
{
String s1 = 'abc';
String s2 = 'ghi';
String s3 = s2;
s2='xyz';
System.out.println(s1+s2+s3);
}
45.public static void main(String[] args)
{
Sample s1 = pinc();
System.out.println(pinc);
if(instance pinc)
{
System.out.println(pinc);
9
STRINGS PROGRAMS
}
else
{
System.out.println("Oak");
}
}
46.public static void main(String[] args)
{
String s1 = "ABCD";
String c=a.lowercase();
b=a.lowerCase('a','d');
b=a.tolowercase('b','c','d');
system.out.println(c);
}
47.public void main(String[] args)
{
str1 = "abc";
str2 = "def";
System.out.println(s1+s2);
str2 = "ghi";
}
10
STRINGS PROGRAMS
48.int i = (int)Math.random();
49.Given a string replace all the digits in the String with empty space.
eg-Fr33Zer
ans:FrZer
50.Given 2 numbers,calculate the hcf of the numbers,Eg -26,38.(26-2*13,38-2*19).Ans-
2
51.Given an array of numbers,find out the largest and smallest number and swap there
places.
52.Given 2 strings,merge the string,replacing any duplicate characters in it.Eg:"hello"
and "World" Ans-"Helwrd"
53.Write a program for two Strings rotating manually?
54.Write a program where the same character is find in the String.
55.Write a program to find number of numerical digits ina string.
58.How to get the matching characters in a string?
59.1.Write a program on
input :a,b,c,d,....,z
11
STRINGS PROGRAMS
output :a=1
b=2
.
.
z=26
60.Write a program on
input :xyz*abc-Hello*abcd
output:zyx*cba-olleH*dcba
61.Print the given string in reverse order.
62.W.A.P to reverse the String word by word
I/p :I.Love.My.Country
O/P :I.evoL.yM.yrtnuoC
63.Write a program to count number of digits in a given String.
Enter a String Sam1sun2dar3
no of digits =3 those are 123
64.Write a program to print the count of the side by side Character same?
Example: Enter String:Ramaa
output :Ram2a
12
STRINGS PROGRAMS
65.Write a program to Convert Number in to Characters
Enter the Number=357546
three five seven five four six
66.Program on resversing a word in a string
Eg:Hello World
o/p:dlroW olleH
67.Run length encoding of a string.
68.Write a program to check whether the string is pallindrome or not?
13