Strings Programs
Strings Programs
1.Reveres a String?
package com.cjss.programming-interviews;
4.Write a program to check given String is pallindrome or not not by using reverse().
1
STRINGS PROGRAMS
8.Write a program to count number of words in a String
12.Write a program to check whether the given two words are anagram or not.
silent,listen - anagram
listen,enlists -not an anagram.
2
STRINGS PROGRAMS
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
3
STRINGS PROGRAMS
d)public void suspend()
4
STRINGS PROGRAMS
c)toLower()
d)split()
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);
}
}
6
STRINGS PROGRAMS
30.Write a program to print number of words in string.
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
8
STRINGS PROGRAMS
public static void main(String[] args)
{
String s="This is a line";
String[] tokens =s.split(" ");
System.out.println(tokens.length);
}
}
9
STRINGS PROGRAMS
}
else
{
System.out.println("Oak");
}
}
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
51.Given an array of numbers,find out the largest and smallest number and swap there
places.
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
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
13