0% found this document useful (0 votes)
4 views11 pages

String Handlng

The document provides an overview of string handling in Java, detailing various methods of the String class such as trim(), toLowerCase(), toUpperCase(), length(), and more. It explains how to create string objects, input strings, and compare them for equality or sorting. Additionally, it includes examples and syntax for each method, as well as some multiple-choice questions related to string operations.

Uploaded by

alphonsajolly02
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)
4 views11 pages

String Handlng

The document provides an overview of string handling in Java, detailing various methods of the String class such as trim(), toLowerCase(), toUpperCase(), length(), and more. It explains how to create string objects, input strings, and compare them for equality or sorting. Additionally, it includes examples and syntax for each method, as well as some multiple-choice questions related to string operations.

Uploaded by

alphonsajolly02
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

String H a n d li n g

CHAPTER A T A GLANC
E

.
String Class Melbods

'
_trim ....:.. ,' 1
__.:..1> . 1ot :p pe ~ ( ) IJ1Cha,Aq l / I ,~,,,,,.or /' I ,- ,,,.,. i/ I oom~-" To~I
' --eq_,-'_u_als-'-'-1:..,_ -
-_re_Cas
_e__,/
j concat / gn_o
-"'
indc.~or ( )
I __ _
,

101,o\\erCa..~ ( ) length ( )

r-\ aJu~'eO- f ! Jitb 11substriJng / I repJlace 11 comparcTolgnureCas' e j


1 / eods\Vi1h / I starts\V

1 1iiYS$~W§ 11i •)#s•§il•t•l§~\ ' '' '


1M¢•l;it ¢
1
a class String in [Link] cters. Java provides
ing : A ·str ing" is a ten n that refers to a se1 of chara .
I. Str d as variables of type String
ose ob jec ts ca n be tre ate
package wh
uffin"); ral .. \fuffin ". fl
2.• String s= ne" String l"M an object of class string which is injtia lized Lhe string lite
In the above s tatement. s
is
= "Muffin":
is equi\alent IO String s
a string:
J. Different \\ ays 10 input a use r de fined metho d : void check (St
rin gs )
x= sc.
- String as a pa ram ete r of
sca nn er sc= ne w Sca nn er ([Link] r calss: String
method of
- String input using next ()
er class.
next( ):
ing inp ut usi ng rea dL ine () method of Buffered Read
- Str
(): Sys [Link] )).
Siring v= [Link]
bu f = ne " Bu ffe red Re ad er( new lnpu1S1reamReader(
• Buffered Re ader listed below:
s· String class methods are
4. \lethods of Siring Clas subs1ring(i. J)
co nca 1()
trim() s1ar1sWi1h(s)
equals()
end sWith (s)
tol owerCase () equal slqno reca~e(s)
value Of(t)
tolJpperCase() compareTo()
length () compa re To lgnorecase()
cha rAt(n) replace( c I .c2)
index Of() sub string(i)
la.\t lndexO f ()
Siring Handling
. after removing leading and
5 'T\....• of the string lta'j'
· u nn(): This method of string class returns a copy 11\
spaces
Syntax: String variahk = [Link]();
Example: String x = "Pan Cakes"
Siring y = "Pan Cakcs".trim():
[Link](x);
[Link](y):
Output: Pan Cakes
Pan Cakes (Spaces trimmed off from beginning & end ) . t lower case and returns th
6· toLo werCase(): This method converts all the letters I·n the string O e resu1hr.
string. 1
Syntax: String variable = [Link]();
Example: String x = "Check this Out".toLowercase();
[Link](x);
Output: check this out
· to upper case and returns the resu
7. toUpperCase(): This method converts all letters ofthe string . 1ttr~
.
string
Syntax: String variable=[Link]()
Example. String x= "Check 2 this Out!".TOUPPERCASE();[Link](x);
Outpu.t: CHECK 2 THIS OUT!
8. length (): This method returns an integer number that represents the total number of characte!'I b
the string.
Syntax: int variable=[Link]();
Example: int I = "string!! handling".length();
[Link](!);
Output: 16
9. cbartAt(): This method returns the character at a specified index from the string.
Syntax: char variable=[Link](integer variable)
Example: chart t = "My country is my pride".charAt(7);
[Link](t);
Output: t
IO. iodexOf: This m_e tho~ returns an integer number that represents the index where the character/s1ril1f
exists in the mam stnng.
Syntax: in k=[Link] (character or string);
Example: int k = "Country Side!".indexOf(!);
Output:12
11. lastlndexOf: This method reterns an integer number that currao,t
of the character/string in the main string. represents the index of the last oc
Syntax: int variable = some [Link](charact .
er or strmg)·
ExampJe: int x = ''Hello lulla". lastlndexOf ("I"); '
[Link](x);
Output: 9
r
coofertiog other datatypes' t0 String t
1:• ()sing valueOf()method · YPe
~yotax: Str'.ng valueOf(long numhcr);
Stnng valueOf( int 1111 ):
General format :
String valueOf(datatypcvarinblc Name)·
, {)sing toString() method ·
r .. neral format : String variable = W
v• . rapper chs 0 f d
£~ ple : mt a = S0; String num = lntc .' -.~ atatypc 10 convcn.10\tnngfhLcrdl ~4n.J>lc 1
01 . . r [Link](a)·
comparing strmgs aor equality: -
1.!,
Strings I, s2:
/ assume that values are stored in sl and s2•/
i,oolean result=[Link](s2);
" If sl and s2 are exactly same result is t rue e1se result IS. false'/
b()o\ean res= s1 .equalslgnoreCase(s2);
('If sl and
• s2 store
• same strings wh IC
· h may d'1ffer m • case (cap11al/small)
. . true else ·Jt gJ''f:5
it gives · false •
it Companng strmgs for sorting:
String sI, s2;
1•assume strings stored*/
int d=[Link](s2)
If the method returns d<0, means sl <s2 in terms of its ascii codes.
d>O means sl>s2
d== 0 means sl is same as s2.
15. ComparetolgnoreCase(): This method the case compares Lhe two strings alphabetically ignoring the
case differ and returned value = 0 ⇒ strings are same
< 0 ⇒ first string lesser than second string
< 0 ⇒ first string higher than second string
Syntax:
int variable=[Link] To Ignore case (somestringed):
Example:
String sl = "HELLO";
String s2= "hello";
String s3= "Hello";
int vi =[Link](s3);
int v2=[Link] Case (sl);
[Link](vl + "\t" + v2);
16 Output·· O O • d ·integer code r,or ·its convers10n
k board has an associate · ·
10 bmary
· ASCU c~des: Every ch~racter ons~iI code. ASCII stands for American Standard Code for Information
form. This integer code 1s called A
Interchange.
65 90
Range of ascii codes from A to 2 : to
97 122
Range of ascii codes from a to z : to
48 10 57
Range of ascii codes from Oto 9 : ·
String HandliJ1g
ac e( )• Th .1
- sa ne w s1 rin
fe r re pl ac in g a ll oc
g1 ha trc su lts a t
cu ra nc es of lh c 0 lc!cna,
'II•
~.
17 . re pl sm c1ho d re 1u rn .
. •

in th e m ai n S I"ri ng w uh th e ne w ch
. ar ac te r. ar).
cs 1r in g. rc pl ac c( ch ar o ld c ha r. ne w ch
ah lc = so m
Sy nt ax : S tr ing va ri 'I'. 'm '):
= "H cl lo ".rcp la ce (
Ex am ple: S tr in g n
):
Sy st e m .o ut .p rin t( n Cnd Of the
O ut pu t : H c rn m o rin g w hi ch st ar ts fr o m in de x till th e OJi ,
st
in de x) : Th is m e th od rc w rn s a ne w
18. s u bs tr in g(
s tr in g. r va ri ab le )
m es tri ng .s ub slr in g(in tc ge r nu m be r o
bl e= so
Sy nt ax : S tri ng va ria (4 );
pl e: S tr in g p= "c ut it o ut ".s ubs tri ng
Ex am n inde .
O ut pu t: it ou t rn s a n ew s tr ing w hi ch starts from sta X~r,,
de x) : Th is m et ho d re ru ·
rt in de x, en d in
19. s u bs tr in g (s ta
I.
e n ds a l e nd in de x- in te ge r) ;
bl e= so m es tri ng .su bs tri ng (in te ge r,
Sy ntax : s tr in g va ria (0 .3 ):
e: S tr in g p = "C ut it o ut ".s ubs1rin g
Ex a m pl argulllt;,,
s tri ng st arts w ith th e string
O ut pu t: C ut ea n va lu e tru e if th e m ai n
s W ith (s ): Th is m e th o d re tu rn s a bo ol
20. s ta rt
e.
e ls e it re tu rn s fa ls With (s1r ing)
: bo ol ea n va ria bl e= so m es 1ring .s tar1s
Sy nt ax );
pl e: bu ol ca a v= "Cu t".stan s Wi1h ("c"
Ex am g argullke
O u tp ut : fa ls e if tJ1 e m ai n s tr ing e nd s w ith th e st rin
ol ea n va lu e tr ue
nd s W ith (s ): Th is m e th od re tu rn s a bo
2 1. e
.
e ls e it re tu rn s fa lse
Synt ax : ith (s tri ng )
so m es tr in g. en ds W
bo olea n va ria bl e=
Ex am pl e:
nds W ith ("t"):
bo olea n v = "Cut ".c
O ut pu t: tr ue

T IO N S
SOLVED QUES Sy st em .O ut . pr in t( x.
eq ua ls( t) );
(b ) false
\ \ 1111111 (a ) tr ue
~ M ul ti pl e C ho ic e Q
ue st io ns
(c ) E rr or
(d ) 1

of be lo w code: A ns . (a )
J. W ri te th e ou tp ut t of be lo w co de:
R eu se Re cy cl e" :
e 3. W ri te th e o ut pu
S tri ng t = "R ed uc Re us e Recycle " :
S tri ng x = ne w St
rin g (t ) ; St rin g t = "R e uu ce
= = t) ; ing (t);
Sy st em .o u t.p ri nt (x St rin g x = n ew S tr
(b ) fa lse . r( x. eq ua ls lg no re C··•-··
(I ll
·
(a ) tr ue Sys te m .o ut .p rm
(d ) I (b ) (al s•·
(c ) E rr or (a ) tr ue
A n s. (b ) (d )
of be lo w code: (c ) E rr or
2.
W ri te th e o ut pu t
= "R ed uc e R e us e R ec yc le " ; An s. (a )
Si ri ng t
S ir in g x = ne w St ring( r);
,., ;,, ,,, : I/C S E ) -
10
l'hl' nu•lhod rnm1mrfl,, I)
J- • . ' return .
1,,,1 strin~s 11re l'llUnl : s - - if 1I. Which of the followlnit Is lht• rnrrccl output
lflll'
l'' ) (I>) of IIH· lll'low slnlcnll'nfs'/
(,·) ll (cl) False String sir = new String() :
l .) Sys1c111.n111.prin1("Thc new si ring is" + sir):
111'· t
· \\'hill is the output for the ht•lo . ( 11 ) The new sl ring i:,
~- . • " w Sltt1,•mcn1 ·~
s~stt'[Link]( Saw ckctrkit . · (Ii) The new siring is null
nd
·. • ·01" 1\ 'b') + I )·,
•,11,kX Y'' W!lll'r". (c) Exccplion
(d) The new string i~ ~Ir
(11) _1 (I>) 0
Ans. (a)
(d I (d) - 1
12. _ _ _ _ C'l nss Is used to ronvcrt a 1,rimillvl'
(/!)
\\\)• d11t11 ty1>e to Its l'Orrcspondinit ohjcl'I. 120221
Gin' the output of the folio Wtn
. g Sll'ing
(). . (11) St ring (/,) Wrapper
methods: "MI SS ISSIPPl".indexOf('S') +
(r) System (ti) Math
"MISSISSIPPl".lastlndex('I')
12022]
Ans. (/J)
(a) to (b) 12
(cl 20 (cl) 11
W- (/,)
l;lA Short Answer Questions \\-
7. Whal is lhe output for: I. Give the output of the following:
[Link]("Malayalam" . replace ('a'. Siring n="Computcr Knowledge.";
'z') . substring( 3.6 )): String m= "Computcr Applicntions";
(a) Mzlzyzlzm (I>) Mzlayalarn [Link]([Link](0,8).concat(m.
(c) cyz (d) zyzl
substring(9) ));
IDS. (c) [Link] .print In ([Link]("e")) ;.
8. The java class S tring is in _ _ package.
Ans. CompulcrApplications
(a) [Link] ring
ll'UC
(b) [Link]
2. Write the output of the following:
(c) [Link]
(i) [Link] ([Link] Uppcr
(d) All of the above
Casc('R'));
Ans. (b)
(ii) [Link]([Link] ppcr
9. Siring s = new String(): will create an object
Case('J '));
of String with
(a) no characters
Ans. (i) true (ii) J

(b) one character 3. Write a statement ench to perform the following


(r) space character task on a string:
(d) none or the above (i) Find and display the position of lhe Inst
Ans. (a) space in a strings.
IO. Which of the following expressions are invalid/ (ii) Convert a number stor ed in a s tring
incorrect '? variable x to double data type. 12011 1
(a) String str = s l - s2 : Ans. (i) [Link]([Link] lndexOf(' ') + J)
(b) String str = sl + s2; ; II Please note lastl ndcxOf returns the
(r) boolean x: = sl <== s2; index, + I gives the position
(d) boolean y = s I = == s2 : (ii) double.: d = [Link](x):
Ans. (a)
String Hafldli11g
4· Slate the . string fuoctions :
purpose and return data type of t he ronowing
(i) indexOf( )
(i i) compareTo( ) character in a stri~g. . .
Ans. (i) It returns the index of the first occurrence of a I if the first st rmg IS less than the s
_
strings and returns 0 I·r they are same,
.. It compares two
(11) eC-0
l'-J
string else I . if first string > second string.
S. Write the return type of the following library function s:
ll11,
1
replace(char, char)
Ans. String
6. Write a statement each to perform the followmg. k a string:
tas 00 . ble wd
· the vana
(i ) Extract the second last character of a word stored 10 ·
(ii) Check if the second characte r of a string str .is •ID upper case.
Ans. (i) char x = wd. chartAt([Link] th( ) - 2);
(ii) boolean y = Characte [Link] ( [Link]( 1));
7. (a) State the output of the following program segment.
String s = "Examination";
int n=[Link]();
[Link]([Link] sWith([Link] g(S,n)))) i
[Link]([Link](2) = =[Link](6)) );
(b ) [Link] (xl3 )); [?0111
Ans. (a ) false
true
(b) Big data
8. If String x = "Computer";
Stringy = "Applications";
What do the following function return for;
(i) [Link]([Link](l , S));
(ii) [Link]([Link]([Link](4)) );
(iii) [Link](y+[Link](S));
(iv) System.o [Link]([Link](y));
Ans. (i) omput
(ii) 4
(iii) Applicationster
(i\·) False
9. Write statements to show how finding the length of h
8 i
length of a String object str. c aracter array char I I differs from find ing 1
Ans. The program code is as follows: poJJI
char arr[]=new charf 10];
int len = [Link];
Syst_em.out.p~int("Length of the characte r array is : + 11
.
String str = Embrace your blessings "; 1en),
int I. = [Link] (); //Note the parenthesis () • . .
. ., . ("L
[Link] [Link] engt b of the stnng
. is : "
+ I);' tn f1nd1ng length of the string

7~tk ~ Computer Applications (]CSE )_ 1


0
\\'IUII Is the out1mt of' the f'11II
,o. .,, . owtnll :
(i) sysh [Link].11rlnlln ("l'our ·"' + 4 + 2
[Link],,(11•,our :"+ >:
12 2
till Strln1t SI = "Ill"; Strl Ill( S2 + 11:
. • "Ill"·
Strini: S3 -= "then•": '
Strlni.t S4 = "hi";
Sysh'm,[Link](S
· ·I + "t'(IU11ls11 + Sl + .. ..
s,•sh•m.0111.,,rlntln(SI + 11equ11b1
. ., ' • + Sl.c1111111~1s211:
+ s \ + 11 ..
Sysh' m.0111 .prlnlln(S I + "
'
'.
cc11111ls" + s + .. ..
► + Sl.t111111!11SJ 11·•
4
Sys1t·[Link].11rintlnfSI + "( I,',, ' ' + Sl.t•1111111~{S41J;
•i) four :42 IIA!uulNll(norcl'nN I, "+ "'4
r, + " ," + [Link](flflrt0tiitl~4JI;

Ani, I
four :4
(11) I lh.:quals hi ➔ lruc
H lcqualsl hcrc ➔ fill sc
11 l cquc1i shi ➔ fals1.:
HIE411allgnorcCaschi ➔true
. the data
11. Stale " type and values· of a an d h allcr the following segment is c"ccutcd.
11
String s l = Computer•, s2 = 11 Applicution ;
o= (s l .compareTo(s2)); 12-0111
b= (s [Link](s2));
Ans. Datatypc of a is int
Datatype of b is Boolean
a=I
b = false
12. What will be the output for the following progrum segment :
Strings = new String("abc");
[Link] ([Link]());
Ans. Output : ABC
13. State the values stored in the variables strl and str2
String sl = "good"; String s2 = "world matters";
String sir I =[Link](S).replace('t', 'n'); 120IJI

String str2= [Link](strl);


Ans. strl = "manners"
str2= "good manners" r
l4. (a) Whal do the following fu nctions retu n for :
String x = "hellci";
String y == "world";
(i) System,[Link](" + y); ,
h
(ii ) System,[Link]([Link] ( )), .
(iii) Systcm,[Link](".charAt (3)),
. . t rintln(".equals(y))i
(1v) System,ou •P Ca\·e( ) and u,u1,perCasel ) methods.
(b) DilTercntiate between toLower ·
Siring Handling 253 I
Ans. (a) (i) hcl/owm ltl
(ii) 5
(ii,) I wer ca~c , wherc;,1 \ tr)UPPtr< .
f. ,irin g to IO -:>,
(11·) fal,c whc l!\" ,1
vcr1, a I • ·1J11f
fl Ill: • . rrcr e,;(l',C.
wcr C:l'C rnc thud ru11
(h) tnl.o ( . , iring 10 u
nwt hnd L"llll \l. 11' :ill rhc alrh ahc h O
ti ·

,·.g . Sr, rng 1 - .. , kilo":


Srrinl,! 1 = t.10Lo"c rCaM;( J;
Stri ng: = [Link]~c( J;
Sy~1cm.ou1.prin1 (Y +" "+z);
Ou1pu1 : hello HELLO
IS. Wha l will the followin g code output ?
String s = "malayalam"
[Link] ([Link] exOf('m') );
Sys [Link] .println ([Link] tlod exOf('m') );
Ans. 0
8
ram segment:
16. [Link] e the output of the followin g prog
String strl = "grea t"; String str2 = "minds";
t([Link]( J)) );
[Link] (str l .substrin g(0,2) .conea 1211,
.to UpperCase())) );
[Link] ( ('WH "+ (str l .substring(2)
Ans. Output:
grinds
WH EAT
17. What is the dat.a type returned by
the library functions:
(i) compareTo ()
(ii) [Link]()
ger data type.
Ans. (i ) compareTo( ) returns result of inte
(ii) equals( ) returns result of boolean
data type .

18. How does java implement a strin g ? · lemeD!t'li


· ,mp
· van•a bl e 1s
A st nng
Ans. Java implements a string. as a contigu · racters •
ous sequence of cha
as an object of class Strmg.
J9. Stat e the output when the following
program segment is executed:
;
String a = "Smartphone", b="Graphic Art"
String h =a.s ubstring(2,5);
String k= [Link](8).toUpperCase();
[Link] .println(b);
pt11:
[Link] ([Link](b) );
Ans . Here, h = art and k = ART
Output:
art
true
is the difference in the cl
,\'~111 f
~ c 011jccts o class Strin g arc asses Stri
of . '. nK nnd StrlnKllufTcr ?
. r~ I or at the end of that . fixcu length. I le . . · .
,, idd C
01 stnng objec t• nee, 1n,cr1111n 111 diarnclcr-. or , uh-.,[Link]~ JO · Ih .
,0g1h can be changed. Hence, the ,.•·r'~.'. 11 ~t pm,ihle. ·1he c
l~ ka 111 Stri nl(Bu t fcr da" crea te, ..iring , who<,c
which pac ge are the two clus , ,l ul IC,lllon~ ·ir '
. · ' c pm.,.·1,1c 111
. .
1he ,amc , 1rrni uh Jett.
.
:I• 10 tang package. . ses StrlnK nnd Strlnl(lluffcr denn ed ?
l~1•a.
i'.~ (.~plain briefl_y ho~ java ~111nnges strings '! ·
I' 1,a handl es its strings using two cl· .. ,
Ja . .
·l f ,he~c classes. T hey are not impt ,<1sscs ·Stnno0 ,m . dS •
• trmgBuffer. Si ring., arc ncatccJ ,1, the ohicc ·
11 t,
1e01entation of strings as ObJ·e cmcn t . .
tcd •,s . . f
' · •'.rr,,y O chara cter,.
I01 P
•rations arc applied on strings chs make ' ·stnng I1an<11·mg more .
11J)'' · ratcr than · · fl cai-.y <1nd man;igct1h lc 1n iav;;i a_<,
trings and even string numb e array o c iarac tcrs. All other data type., can l>c conve rtcd
tt' ~
be applied to the strings b rs ti
can get convc t d
. r c l o numhcr data type!.. Many manip. [Link] t;;i\11..., ,..
can 1
. - the two ways in which Y e various mcth Od ·u ·
1 s prov, cd in cla~!ic!i String· · and Stnn · ,.1-1.
lr'u ffer.
~ ';~\ir ing str=" TOG ETH Ji;~ can assign a text string "TOG
ETHER" to a string variable, say, i,tr.
" (b) char arr!]= {'T','O','G','E','T','H','E','R'}·
String str= new String(arr); '
't Write the java statements to perform the follow ·
. .. . .
ta) Jmttahse a vana ble city to store "DELHI".
mg .ft ks
w S on strmg . s:

(b) Accept the addre ss from the user.


(c) Print the numb er of chara cter in the above enter
ed address.
(d) Concatenate City with Address and store as string
PostalAddr ess.
(t ) Extract 10 chara cters from 1st character to
10th of PostalAddress.
(J) Extract the last chara cter of Posta lAddress.
(g) Compare City with "Ghaziabad" and store the boole
an result in variable 'bool'.
{h) Print the position of first occurrence of the letter
'B' in string City.
(i) Print the position of last occurrence of the subst
ring "DEL' in the string strl.
(i) To replace all occurrences of letter 'm' by letter 'M' in
the line of text "my mother is very lo,ing".
(k) Compare name with "KARAM ARORA", ignor
ing the case matching. Store the boolean result in
variable bin.
(/) Compare the ascii codes of two string variables strl and
str2, and store the returned result in
'compariso n' variable.
(m) To search a sub-s tring srch_ str in anoth
er string orig_str. Assign the returned position to pos.
(n) To search a sub-s tring srch_str begining from th
10 position character in another string orig_str.
Assign the retur ned position to posl.
(o) Extr-c1ct a sub-s tring from a string str from 4th 'f
pos1 10n to 10th positi , •
on and assign it to str2.
(p) Replace all occurences of chara cter chi by ch2 in the
string str.
(q) Reverse a strin g "SUN MICROSYSTEMS"
. . .
{r) Remove all leading and trailing white spaces
from a strmg stored m variable stng.
(s) Change the case of all characters of a string str
to lowercase.
(1) Change the case of all characters of a string str2
to upp,e~case.. '
(11) p . 'H
rant ello Boss, I'f a give
. n name starts with the letter Z [Link] 1f t. he name s last letter
is 'a' then

Print "Good Day Boss,,. Make sure that the first .
and last letters are not spaces.
h•) Conve rt the number 56.78 to its equivalent Stnn~. . "
(11, Ir . dd '" . .
1 · the pm code of the a ress e nds with 34 then displa y yahooooo. Otherwise display "I'm sad"

String Handling -
R ,1dcr ([Link] ));
. . . "l>l l lll"· (11pu1 S1rcanl c,
1\ ns. (a) S11111i,: 1.·11y- · • • ,,(new
1
11 tl 1•1cdl<,ll' l
(/•) B11fk11.•dl h-111k1 oh Ill'\'' 11 11ddl.c;. ~,·")
'
;
''l'I . l•111c1 yo111
sv~11.· 111.11111.p11111 I11 1 cn~1. • . • . in the address")·
. ( 1. O
f ·haractcr s ,
S11 ini,: 11.ld11·~, 11h , c.1111 nw • 11 mhcr c
• ) -l "j, 1hc II
(1') s , ,11·11111111 p1111thl(H1hh r s~.ll' 111,t th (
. .,,i(·uldrcsi-):
(,/) Sttlll!,! p1,~[Link]\dd1c~~ [Link](, ' . tO)·
. . .. • 1hstnn1,t(O, '
\I') St11ni,: l'\t1.1ctnl = 1111~talAdl Iicss.~I. · I. ,th() - 1);
. . (Address. cng
0st
l/) dm1 d1 - p11~[Link](P •'
ld h1h1ka11 h,1111 =rity.l.'quals("Ghazialrnd"):
(/,) int 1 =rit~.intk1,Of('B'):
(i) int pl1~ =[Link]~t lmkxOl'("DEL"):
lil St ring s I= "my mother is very loving";
Strine. s2=s [Link]('m'.'M');
~ c ("KARAM ARORA");
\I.) boolean bln=[Link] ase
(/) int rnmparison=[Link](str2);
(m) int pos=orig_str.indexOf(srch_str);
(11) int pos t =orig_str.indexOf(srch_str,10);
(o) String str2=[Link](4,11);
/" It extracts the sub-string from 4th position, here 4 specifies the beginning index and 11 Sjlc{',:
the end index, i.e., the stopping position. This 11th position character is not included in sub-sin:.
(p) String str_replaced= [Link](chl ,ch2);
(q) StringBuffer s="SUN MI CROSYSTEMS"·
'
[Link]( ); /*The reversed string gets stored in same objects*/
(r) String s=[Link]( );
(s) String s=[Link]();
(t) String s=[Link]();
(u} String name= "SMITH JOHN"·
'
String nam = [Link]( );
if( [Link]('Z'))
[Link] ("Hello Boss");
else if( [Link]('a'))
[Link]("Good Day Bo ")·
. , ss '
(v) S~n~g y=[Link](56.78);
(w) iJ ([Link]("34")- _
--true)
System
' o t · ("
· u .prmt Yahoooo !!")
else
[Link]("l'm sad");

7~ J Computer Applications (TCSE


)-10
tt ibt output for the folloWi. .
• ''~
0
"::::"Toda) is Test"· ng. (20171
,.[1111" " . . '
~,~ttl11•out.p~ntln ([Link](T));
~- -telll·[Link]([Link](O 7 )
•• O"~ t + " "+ "h •
nohday");
r vl) 1ioda, is Holida\
l . -
Gi'-e the output of the follo"ing code:
(2017}
,- ·no A="26''. B="lOO"·
~rt- •
. . D=A+B+ ''200"·
,trtDg '
; "::: [Link] (A);
11
f\ :::[Link](B)~
111 •
intd:::'.\ +y~
~,~tern,outprintln("Result 1 = "+ D);
s~-te([Link]("[Link] 2 = "+d);
~~ull l= 26100200
c-- . , l"'6
Re5ult - = -
(?019, 111
... ,,rite the return data type of the following function.
• a ends"ith O (b ) startsWith O (c) randomO
o- ~ 00olean (b) boolean (c) double
(?018}
is.. Ghe the output of the follo"'ing string functions:
at ACHIEYE~IE~'T".replace('E'. 'A')
lb "DEDICATE".compareTo("DEVOTE")
~ {a [Link]\ '~\.1Ai'IT
(r,\ 1.

-I

You might also like