Professional Documents
Culture Documents
Tcs Ipa Java
Tcs Ipa Java
1. Strine ()Oncatenatlo n
3. substrinc()
4. trim()
6. lndexOf(I
c=c+l;
}}
System.out.prfntln(c);
for(lnt l=O;i<5tr2.length();l=f+2)
{
Systi!m.ouLprlntln(str2.substrlng(l,l+ll);
)
Sysb!m.out.prfntln(day};
System.oo t.prlntln(m onth);
System.ou t.prlntln(y earj;
I}
Strl"lf) ns • sir.spilt(" 0 );
String nm,.••;
}
nstr-nstr+" " ;
}
Sysb!m.out.prlntln(nstr);
Probleml-Solution
• Pri nt all odd numbers in a range (read the starting number and ending
number)
public static void main(String[J args ) {
Scanner s= new Scanner(System. i n);
// read the range
int start• s . ne~tlnt() ;
int end = s .nextlnt ();
System.au~ . print In( "Printing odd numbers from "+start+ " to "+end);
//use a loop to pr1nt odd numbers
II n,2- 0 mean~ n ~seven
for ( int i =start; i <=end ; i ++){
if(~2 I• 0)
System.oirr.println(i };
}
}
Problem 2 -Solution
• Read two number and find the value of one number raised to the
power of another.
public static void main(String(] args) {
Scanner scan = new Scanner (System . in);
//read x and y
int x • scan .nextlnt();
int y • 5Can .nextlnt();
int result•l;
II x"y
for (int i~0; i <y; i ++){
result = result•x;
}
int n = 1234567 ;
•
lxtract ,he Ja,t digit of the nulllber n by n~lO
~pdnte the value of n by n/10 an1 repeat the above ,tep
t i l l n i• not equdl> too.
}
Problem 4 - Solution
• Read n number using for loop and find the biggest number, smallest number
and average of all numbers.
public at■tic void 11• l11(Sl l'l11d ] •• 11•) {
Sc.inner u~n -=- nb.l Sc,1nner(Sy,te••· l r1);
I I hnw ltlil ny nrnnhP r "
int count• scan .nextinl () J
int bi3-e~ s•~ll•8> sum =0, JVg ◄;
Sy~ t en, . out. swl.n Lln( "'llla,;g~ l riuatJur : "+blu-t.. ~nwll e.!:. L nllll..00.,·: ..+11,1 .tl l+"' illverilge: "'.+st.1a1/,ou11l) :
)
Problem 5 - Solution
public static void ,nain(String[] args ) {
int aaount - 25561;
int denaain•tion_coun t •5; // l, 10, ~ , SOO, 29UO -· can ndd r -~
/ declJ~e vJriMbles to , · oru denoon1nat1or L<>unl
int _2088Count•0, _500Count• 0 , _100Count-e,_10Count =0,_l(ount •0;
l"OII -,unt
/d~vide ~ t"J ~ te d~natton end r~ctuce cNr-"d' -in.antM'
for ( lnl 1 a. e, l < \i.-..,...ii.Uu11_'-uw.nLj 1-+'"' ) (
if ( -.r,t >- 2908) {
_200'IC.,.,..t • ucunt: / 2800;
aou11r- ... a110Unt - _2eeecOU"lt .. ieoo; )
els• lf ( - >• 590) {
S80CC1#1t a MOl.inl / 580;
MDiJ"'lt .. Pol,Jlt .. _SOICOi.ln't • see; )
w• if c-, ,. tee) {
_100CCU"t -"' ~n~ / 180j
MDUTft - oP"""-"'t" .. _1eeco.mt • 100; }
WO if (-.,,t >• 18) [ .. !..r<T ru lt
_11(0<,nt • ...,..,.t / 10; Syn,.. ou< .prlntJnL280i'Caunt• ·-2088 ") ;
~ t • lf1t - 10Cou "lt • Le; } Syn•.ou< .prlntln(_~OCount♦•·- " ) ;
int X = 1234567 ;
int C = 0 ;
while (x > 0){
Prints the number of digits I n the
X /=10; given number.
c++; Output : 7
}
System. out .println(c);
_j
Test Your Knowledge
• What will be the output of below program?
• Example
• Input : 2030
• Output: 5