Chap 03

  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Chap 03 as PDF for free.

More details

  • Words: 3,039
  • Pages: 26


 "  (   /   "78/4'9"+ "%8 :;"1'(<""='='&,B6 %B 1%$B @C2/61,+!(6&(2'6@+309">'?'.'@' RSB6 :;"1'(@+30#='5,+1'( ='6'"C/6='&,B6DH'6F9"!:(<1(0>'?'.'@' !5$.1#H'@*S6='&,6B !(6&(2'6@+30&/6:(> 7/='&,B6!(6&(2'6<++#7/1 ='RSB6G52<1H='&,B6if,if..else <# switch  <#='&,6B !(6&(2'6<++ ='R8='RSB6G52<1H='&,6B  while,do..while <# for <#9"D/" 2'$C/6+ "%. 8 1#H'@*S6='&,6B !(6&(2'6@+30<++R2/"

" A (   /  ='&,B6!(6&(2'6@+30 X   X  :;"='&,B6 %B9I29"1'(1='4"5#='5,+1'( ='6'"C/6='&,6B DH'6F>'?'.'@'0%!(6&(2'6@+30&'0(M:<++7/ PQ !(6&(2'6<++D'0#='5,+—  X  Q !(6&(2'6<++#7/1 ='X X  cQ !(6&(2'6<++ ='R8='  X  !5$ @,B G:='&,B69">'?'.'@'.0%!(6&(2'6@+30<++D'0#='5,+ !5$. ='6'" D'0#='5,+C/6='&,B6 0%B %/$M9H "!:(<1(0RSB6.(A0B ='6'".'10L/5 main()!5$. ='6'".'1 ='&,B6<(1C/60L/5 main() <# ='6'"(%$6D'0#='5,+='&,B6DH/G:(7B/$F 1(% %B0%1'( (%$19I20L/5C/6//:.K !:(<1(0.C2'G: ='='&,B6>'$9"0L/5",8" <#07B/&A8"&35='&,6B &35 2'$C/60L/51K.1#,+0' '= ='&,B6 %B(%$19I20L/55,6<&569"(M: %BcQP

    

    





public class Sample { public static void main(String args[]) { Student s = new Student(); String name; name = s.getName(); System.out.println(name); } public class Student {  } String name;  public String getName(); return name; } }

   %! C,8"D/"1'( ='6'"D'0#='5,+C/6='&,B6 %B0%/$MH9"!:(<1(0 

" ( "#'A !(6&(2'6<++#7/1 =' :;"1'(942#7/1 ='I35='&,6B 9"1(% %B"-A ."ED((1)'&D(E0%H' :;".(A6D'067B/"GCRSB6I35='&,6B !(6&(2'6<++#7/1 ='.:(1/+G:52@$='&,B65,6DH/G:"%8 x ='&,B6if x ='&,B6if..else x ='&,B6if <++R2/"V x ='&,B6switch 

" A if ='&,B6if .0%(M:<++5,6"%8 if (logical expression) { statements }

!5$ %B x

logical expression 7/"A-."ED((1)'&D(E

%B942W##,-LE:;"C2/0M#H'6 %B

I"A5boolean





 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 x statements 7/I35='&,6B 95F I35='&,6B %B/$M9H "+#K/1   . ='6'"9"1(% %B"A-."ED((1)'&D(E942H':;".(A6 RSB6 ='&,B6if &'0'(*<&56#='5,+1'( ='6'":;"!J@EI'(ED?3=@56,01G525,6<&569"(M: %BcQ 



A)/0 A 

'f

* ? 1 'A A D0

L'f

L'f

H

H* )/0 A 

  %!$!J@EI'(EDC/6='&,6B if



D,@/$H'6C/61'(9I2='&,B6if 0%5,6"%8   if(radius >= 0) { area = radius*radius*Math.PI; System.out.println(area); }

.'1D,@/$H'6"%I8 35='&,6B %B/$M9H "+#K/1 ='&,B61='4"5H'D,@<:( area <#='&,6B <&56W#. ='6'"9"1(% %B"-A ."E radius >=0 :;".(A6 1#H'@7/D,@<:( radius0% H'0'11@H'4(7/ H'1,+m 1(% %BI35='&,6B 9"+#K/1   0%-%$6='&,6B 5%$@('&'0'(* .%B D,5(7B/640'$   //1G:G52/' AIH"='&,B6    if((x > 0) && (x < 10)) { System.out.println(x); }



&'0'(*C%$"940HG52:;"  if((x > 0)

    

&& (x < 10)) System.out.println(x);

    






  %!%W##,-LE G%B 52.'11'((,"!:(<1(0 %BcQP 

" A if..else ='&,B6 if .G0H0%1'( ='='&,B695*2'"A-."ED((1)'&D(E0%H':;" .K 5,6",8"*2'D2/61'( ='='&,6B +'6='&,B607B/"A-."ED((1)'&D(E0%H':;" .K  .D2/69I2='&,B6 if..else < " RS6B 0% (M:<++C/6='&,B65,6"%8 



 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 if (logical expression) { true statements } else { false statements }

 

!5$ %B x

true statements7/I35='&,B6&='4(,+H'.(A6

x false statements7/I35='&,B6&='4(,+H' .K  !5$0%!J@EI'(EDC/61'( ='6'"C/6='&,B6"%856, <&569"(M: %BcQu





'f

*

A)/0 A 

A)/0 A 

A& 1

A& 1*

L'f

L'f

H

H* )/0 A A& 1

)/0 A A& 1*

  %!,!J@EI'(EDC/6='&,6B if..else  

D,@/$H'6C/61'(9I2='&,B6if..else0%5,6"%8  if (radius >= 0) { area = radius*radius*Math.PI; System.out.println(area); } else { System.out.println(“Negative radius”); }

    

    





 .'1D,@/$H'6"%8*2'D,@<:( radius 0%H'0'11@H'4(7/ H'1,+ m "A-."E0%H':;".(A6 !:(<1(0. ='1'(='"@H'1='4"5H'<#-A0-EH'C/6D,@<:( area //10'
   %!-W##,-LE G%B 52.'11'((,"!:(<1(0 %BcQ 





 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6



"" A if"M ='&,B6if4(7/ if..else&'0'(* .%B R2/"/$MCH 2'69"='&,6B if4(7/if..else /7B"G52/' AIH" !J@EI'(ED %B<&569"(M: %B cQ… RS6B 0%C,8"D/"1'( ='6'"7/ !:(<1(0. =' I35='&,6B %B c*2'"A-."ED((1)'&D(E %B P:;" .K 
 'f  

*

'f $ )/0 A   

*

)/0 A  %

)/0 A  $

  %!.!J@EI'(EDC/6='&,6B if <++R2/"  .'1!J@EI'(ED9"(M: %BcQ…&'0'(* %B.C%$":;"='&,B6if <++R2/"G525,6"%8 if (logical expression1) { if (logical expression2) { statements 1 } else { statements 2 } } else { statements 3 }





    

    





 

D,@/$H'6IH"  if(radius



 

>= 0) { area = radius*radius*Math.PI; if(area >= 500.0) { System.out.println(“Big Circle”); } else { System.out.println(“Small Circle”); } } else { System.out.println(“Negative radius”);





*

'f   )/0 A   



*



'f $ )/0 A  $

)/0 A  %

   %!3!J@EI'(EDC/6='&,6B if <++R2/"   !(6&(2'6#7/1 ='<++R2/"$,60%1(% %B:;"5,6!J@EI'(ED9"(M: %B cQv RSB6.0%C,8"D/" 1'( ='6'"7/ !:(<1(0. ='I35='&,B6 %B P *2'"A-."ED((1)'&D(E %B P :;".(A6
 if (logical expression2) { statements 2 } else { statements 3 } }

 

9"1(%"%8&'0'(* %BC%$"='&,B6 if..else!5$0%(M:<++C/6='&,B65,6"%8

if

<++R2/"G52940H 9"(M:C/6

if..else

if (logical expression1) { statements 1 } else if (logical expression2) { statements 2 } else { statements 3 }

  

 

D,@/$H'6C/61'(9I2='&,B6 if..else if..else0%5,6"%8 if(score >= 80) {  

     

System.out.println(‘A’); } else if(score >= 70) { System.out.println(‘B’); } else if(score >= 60) { System.out.println(‘C’); } else if(score >= 50) {  System.out.println(‘D’); } else { System.out.println(‘F’); }

 D,@/$H'6"%.8 -A0-ED,@/,1?( A*2'D,@<:( score0%H'0'11@H'4(7/ H'1,+zm-A0-E D,@/,1?( B *2'D,@<:( score 0%H'D,86
    

    





("'  %!%1'(9I2='&,6B if..else         

if..else

public class SampleIfElseIf { public static void main(String args[]) { int x = Integer.parseInt(args[0]); if (x == 1) { System.out.println("Value is one"); } else if (x == 2) { System.out.println("Value is two"); } else { System.out.println("Other than 1 or 2"); } } } 

!:(<1(0 %BcQc<&56D,@/$H'61'(9I2='&,B6if..else if..else!:(<1(0"%8. /H'"H' %B:„/"C2'0' '6 XV  !5$!:(<1(0.-A0-EC2/@'0@H' “Value is one”*2'H' %B:„/"C2'0':;"P-A0-EC2/@'0@H' “Value is two”*2'H' %B:„/"C2'0' :;"<#-A0-EC2/@'0@H'“Other than 1 or 2”*2'H' %B:„/"C2'0':;"H'/7B"F 

"& A switch ='&,B6switch:;"='&,6B !(6&(2'6<++#7/1 ='!5$0%(M:<++5,6"%8 switch (expression) { case value 1 : statements 1 break; case value 2 : statements 2 break; : : case value N : statements N break; default : statements N+1 break; }





 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 !5$ %B x

expression7/"A-."E int

x

%BD2/60%I"A5C2/0M#:;"char,

byte, short4(7/

H'",8"

value 1 .. value N

7/C2/0M#H'6 %BRSB60%I"A5C2/0M# &%B /5#2/61,+I"A5

C2/0M#C/6expression ='&,B6 switch .D(@.&/+H'C/6"A-."E %B/'.:;"I"A5C2/0M# char, byte, short4(7/ int1(% %BH'C/6"A-."E0%H'D(61,+H' %B P!:(<1(0. ='I35='&,6B %B P*2'0% H'D(61,+H' %B 1K. ='I35='&,6B %B *2'0%H'D(61,+H' %B i1K. ='I35='&,B6 %B i&H@"1(% 0%B % H'G0HD(61,+H'95F#$9"='&,B6case1K. ='I35='&,B69"V 7/I35='&,6B %B ijPRSB6<&56 C,8"D/"1'( ='6'"G525,6!J@EI'(ED9"(M: %BcQz

 h 1   h 1 $

 

)/0 A    )/0 A  $

j h 1 i h 1YZc9P`d

j

 

)/0 A  i )/0 A  i\ 

  %!4!J@EI'(EDC/6='&,6B switch  

 D,@/$H'6C/61'(9I2='&,B6switch0%5,6"%8   switch (x) { case 1 : System.out.println(“One”); break;

    

    





case 2 : System.out.println(“Two”); break; case 3 : System.out.println(“Three”); break; default : System.out.println(“Other”); }

D,@/$H'6"%.8 -A0-EC2/@'0D'0H'C/6 x D,86


x ='&,B6 break .4$351'( ='6'">'$9"+#K/1   *2'G0H0%='&,B6 !:(<1(0. ='='&,B6*,5G:D,@/$H'6IH"   switch (x) {

break

case 1 : System.out.println(“One”); case 2 : System.out.println(“Two”); break; default : System.out.println(“Other”); }

.-A0-EC2/@'0OneD'052@$Two9"1(% %Bx0%H':;"P x 67B/"GC default.0%4(7/G0H0%1KG52    !:(<1(0 %B cQu <&56D,@/$H'6C/61'(9I2='&,B6 switch RSB6.G52W##,-LE:;" C2/@'0@H' Value is one *2'D,@#C %B:„/"C2'0'0%H':;" P :;"C2/@'0@H' Value is two *2'D,@#C : %B „/"C2'0'0%H':;"<#:;"C2/@'0@H' Other than 1 or 2 *2'D,@#C %B:„/"C2'0'0%H'/7B"F    





 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

  ("'  %!,D,@/$H'61'(9I2='&,B6switch          

public class SampleSwitch { public static void main(String args[]) { int x = Integer.parseInt(args[0]); switch(x) { case 1:System.out.println("Value is one"); break; case 2:System.out.println("Value is two"); break; default:System.out.println("Other than 1 or 2"); } } }

"" ( "AMA !(6&(2'6<++ ='R8=' :;"='&,B6 9%B I29"1'(&,B6942I35='&,B695F ='R8='4#'$(,86D'0 67B/"GC %B(+3RS6B I35='&,B6!(6&(2'6<++ ='R8=':(1/+52@$='&,6B x ='&,B6while x ='&,B6do..while x ='&,B6for 

"" A while ='&,B6while.0%(M:<++5,6"%8 

 

   

 

   

initial statements while (logical expression){ statements   update statements }

    

    





!5$ %B x

initial statements7/='&,B6

9%B I29"1'(1='4"5H'(AB0D2"

x

logical expression7/"A-."ED((1)'&D(E

x

update statements7/='&,B6

9%B I29"1'(:#%B$"<:#6H'



='&,B6 while  . ='I35='&,6B <#='&,B6:#%$B "<:#6H' %B/$M9H "+#K/1   D('+95 %B "A-."ED((1)'&D(E$,60%H':;".(A6 ='&,B6 %B/$M9H "+#K/1 .D2/60%='&,B69"1'(:#%B$"<:#6H' -7B/:#%B$"H'"A-."ED((1)'&D(E9420%H':;" .K  0A|",8"<#2@!:(<1(0. ='='&,B6 %B/$MH9" +#K/1<++G0H0% %B&A8"&35='&,B6while&'0'(*C%$":;"!J@EI'(EDG525,6<&569"(M: %BcQs   A 'A&0 1   'f

A)/0 A MA L'f +H

*

 )/0 A   A # +"# 1

  %!5!J@EI'(EDC/6='&,6B while

 





 D,@/$H'6C/61'(9I2='&,B6while-7B/-A0-EC2/@'0@H' U^ V&A+(,68 0%56, "%8   int count = P;  

while(count <= 10) { System.out.println(“Hello World”);   count++;

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 

  }

D,@/$H'6"%08 %='&,B6 int count = 1; :;"='&,B61='4"5H'(AB0D2" !5$0%"A-."E D((1)'&D(E7/ count <= 10 RSB6!:(<1(0. ='='&,B69"+#K/1   D('+ H' %B"A-."E D((1)'&D(E0%H':;".(A6 1#H'@7/H'C/6D,@<:( count "2/$1@H'4(7/ H'1,+ 10) &H@" ='&,B6 count++; :;"='&,B6:#%B$"<:#6H'C/6D,@<:( count !5$.-AB0H' %#4"SB69"
  %! 6W##,-LE %BG52.'11'((,"!:(<1(0 %BcQt

    

    





"" A do..while ='&,B6 do..while :;"='&,B6 %B :;"!(6&(2'6<++ ='R8=' 0%B %1'( ='6'"#2'$1,+ ='&,B6while!5$0%(M:<++='&,B65,6"%8 

 

   



 

initial statements do { statements   update statements } while(logical expression;



!5$0%!J@EI'(EDC/61'( ='6'"C/6='&,B6"%856, <&569"(M: %B cQPPC2/
A)/0 A MA L'f +H

 A # +"# 1



'f

*    %! !J@EI'(EDC/6='&,B6do..while

 D,@/$H'6C/61'(9I2='&,B6 do..while-7B/-A0-EC2/@'0@H'U^ V&A+(,860% 5,6"%8  



 

int count = 1;

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 



  do {

 

System.out.println(“Hello World”); count++; } while(count <= 10);

("'  %!.D,@/$H'61'(9I2='&,B6do..while public class SampleDoWhile { public static void main(String args[]) { int i = 1; do { System.out.print(i+" "); i++; } while (i <= 10); } }

    !:(<1(0 %B cQ…<&56D,@/$H'61'(9I2='&,B6 do..while-7B/-A0-EH'D,@#CP*S6 PmRS6B .G52W##,-LEIH"5%$@1,+!:(<1(0 %BcQt

""" A for ='&,B6for:;"='&,6B %B :;"!(6&(2'6<++ ='R8=' 0%B %(M:<++C/6='&,B65,6"%8 



for(initial statements; expression; update statements) { statements }

  !5$0%!J@EI'(EDC/61'( ='6'"C/6='&,B6"%856, <&569"(M: %B cQP ='&,B6 for .9I29" 1(% %B ('+.='"@"(,869"1'( '= R8=' %B<"H"/"&H@"='&,B6 while4(7/ do..while"A$09I2 9"1(% %BG0H ('+.='"@"(,869"1'( ='R8='#H@64"2'

    

    





A 'A&0 1

 'f

A)/0 A MA



L'f +H

*

)/0 A   A # +"# 1

   %! $!J@EI'(EDC/6='&,B6for D,@/$H'6IH"='&,B6-A0-EC2/@'0U^ V&A+(,86@(9I2'= &,B6 for0'11@H'9I2 ='&,B6while4(7/do..while !5$&'0'(*C%$"='&,B6G525,6"%8   for(int count = 1; count <= 10; count++) { System.out.println(“Hello World”);



 }

9"1(%"%8.4K"G52@H'I35='&,B6 9%B I2='&,B6 for .0%(M:<++ %B1(I,+1@H'07B/ %$+1,+ 1(%C/6='&,6B while4(7/do..while ='&,B61='4"5H'(AB0D2"4(7/='&,6B :#%B$"<:#6H' %B/$MH9"='&,6B  for &'0'(* %B.0% 0'11@H'/$H'6#4"SB6='&,6B !5$.9I2(7B/640'$`9"1'(<$1='&,B6/' AIH"  for(int i = 0, j = 0; i < 4; i++, j += 2) { System.out.println(i + “



” + j);

}

:;"='&,B6 .%B -A0-EH'C/6D,@<:( i <# j %B1='4"5CS8">'$9"='&,B6 for u (,86 !5$D,@<:( i .-AB0H'CS8" %#4"SB6<#D,@<:(j.-AB0H'CS"8 %#&/6 





 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 ("'  %!3D,@/$H'61'(9I2='&,B6for      

public class SampleFor { public static void main(String args[]) { for (int i=1; i<=10; i++) { System.out.print(i+" "); } } }

  

!:(<1(0 %B cQv<&56D,@/$H'61'(9I2='&,B6 for-7B/-A0-ED,@#CP*S6PmRSB6.G52 W##,-LEIH"5%$@1,+!:(<1(0 %BcQt D,@<:( %B:(1')9"='&,B61='4"5H'C/6='&,B6 for.0%C/+CD1'(9I26'"G52|-' >'$9"+#K/1   C/6='&,6B  for  H'",8" 1'(9I26'"D,@<:("/1+#K/1   .1A5 X   5,6<&569"D,@/$H'6C/6!:(<1(0 %BcQz  ("'  %!4C/+CD1'(9I26'"C/6D,@<:(       

public class VariableScope { public static void main(String args[]) { for (int i=1; i<10; i++) { System.out.print(i+" "); } //illegal System.out.println("i = "+i); } }

 ('G0H&'0'(*9I2'= &,6B  for 9"1(% %BG0H ('+.='"@"(,68 9"1'( ='R8=' %B<"H"/" D,@/$H'6IH"!:(<1(0 %B cQs:;"1'(&3H0D,@#C&/6D,@ 0%B %H'(4@H'6 P*S6Pm !5$942 ='1'( &3H0D,@#C ,86&/6."1@H'W#1'(&30H C/6#C ,86&/60%H' H'1,"0L/5 Math.random():;" 0L/5 9%B I29"1'(&30H #C.='"@" )"A$0(4@H'6m*S6P<#='&,B6 i = (int)(Math.random()*10)+ 1;

    

    





:;"='&,B6 9%B I29"1'(&3H0D,@#C(4@H'6 P *S6 Pm <#2@1='4"5H'9421,+D,@<:( i !:(<1(0"%8&'0'(*C%$"940H!5$9I2='&,6B  while G52


"& ( "MEiZ^dZYkdbPWdPbZF ='&,B6!(6&(2'6@+30&'0'(*C%$"R2/"1,"G52/' A IH" 9I2='&,B6 if <++R2/" ='&,B6 for <++R2/" !(6&(2'6<++R2/"&'0'(* %B.0%='&,B6!(6&(2'6@+30 %B/$MH>'$9" <#>'$"/1'$9"='&,B6 for-7B/ %B.-A0-ED,@#C(4@H'6P*S6um %B4'( t#6D,@//10' >'?'.'@'/"3n'D942C%$"='&,6B !(6&(2'6@+30R2/"1,"4#'$FI,8"G52 ='&,6B  !(6&(2'6<++R2/" 9%B I21," ,B@G:<++4"SB67/='&,B6for<++R2/"D,@/$H'6IH"='&,B6  for(int i = 1; i <= 3; i++) { for(int j = 1; j <= 4; j++) { System.out.println(“i =”+i+“ j =” +j); }



   



 }





 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 0%='&,6B  for %B/$MH>'$"/1 .%B  ='R8='&'0(,68  !5$1='4"5942D,@<:( i  0%H' (AB0D2":;"P <#-AB0 %#4"SB6&H@"='&,B6 for %B/$MH>'$9". ='R8='&%B(,86 9"'$9".-A0-E(7B/640'$ ‘*’   H'1,+.='"@"/#,0"E t (,86 <#='&,6B  for  %B/$MH >'$"/1. ='='&,6B for %B/$M>H '$9"R8=' H'1,+.='"@"<*@c(,86!:(<1(0.G52W##,-LE5,6 (M: %BcQPc ("'  %! 6D,@/$H'61'(9I2='&,6B for <++R2/"        

public class NestedFor { public static void main(String args[]) { for (int i=1; i<=3; i++) { for (int j=1; j<=5; j++) { System.out.print('*'); } System.out.println(); } } }





  %! %W##,-LE %BG52.'11'((,"!:(<1(0 %BcQPm  !:(<1(0 %B cQPP <&56D,@/$H'6!:(<1(0 %B0%='&,B6!:(<1(0<++R2/"4#'$F (M:<++/$M>H '$9"!:(<1(0"%.8 &3H0#C.='"@"DK00'&/6H'<#2@.-A0-ED,@#C|-'bB0/;8 72;f80e %B/$MH(4@H'6#C ,86&/6",8"//10' RSB6(M: %B cQPu <&56D,@/$H'6W##,-LE %BG52.'11'( (,"!:(<1(0 %BcQPP

    

    





("'  %! D,@/$H'61'(9I2='&,6B !(6&(2'6<++R2/"4#'$(M: 

 public class SampleNested { public static void main(String args[]) {  int n1 = (int) (Math.random()*10)+2;  int n2 = (int) (Math.random()*50); boolean flag = false;  int j = 0;  System.out.println("The prime number between n1+" to "+n2+" are ");  for (int i=n1; i<=n2; i++) {  flag = false;  j = 2; do {  if ((i % j++) == 0)  flag = true; } while ((j < i) & (flag==false));  if (flag==false)  System.out.print(i+" "); }  } 

"+

}

  %! , D,@/$H'6W##,-LE %BG52.'11'((,"!:(<1(0 %BcQPP

"& A break,continue"#E>]JE ='&,B6 break <# continue  :;"='&,B6 %B9I29"!(6&(2'6<++ ='R8=' -7B/ %B. @+301'( ='6'"C/6='&,B69"+#K/1!5$='&,B6break. ='9424$35&A8"&351'( ='6'"C/6 !(6&(2'6<++ ='R8=' &H@"='&,B6 continue .C2'01'( ='6'"='&,B6 %B 4#7/>'$9"+#K/1   !5$G:(A0B 1'( ='R8='9"(/+DH/G:940H





 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 

D,@/$H'6IH"='&,B6   for(int



 

i = 1; i <= 5; i++) { if (i == 3) break; System.out.println(i);

}

.-A0-EH' i D,86
   



 

if (i == 3) continue; System.out.println(i);

}

!:(<1(0.-A0-EH' i D,86'$9".4$35 ='6'"'$"/1 .$,6 ='6'"DH/!5$.G52W##,-LE5,6<&569"(M: %BcQPt ("'  %! $D,@/$H'61'(9I2='&,6B break  class SampleBreak1 { public public static void main(String  int i, j, product; for (i=1; i<=3; i++) {  for (j=1; j<=3; j++) {



    

args[]) {

product = i*j; if (j==3) break; System.out.println(i+" * "+j+" = "+product); } } } }



    

    





  %! - W##,-LE %BG52.'11'((,"!:(<1(0 %BcQP  9"1(% %BD2/61'(.4$351'( ='6'"C/6='&,B6!(6&(2'6@+30 %B/$MH>'$"/1 ('. D2/61='4"5 3,f83 CS8"0'DA0 5,6D,@/$H'69"!:(<1(0 %B cQPc RSB61='4"5 3,f83 %BI7B/ outer <#0%='&,B6 break outer; -7B/ %B. ='942!:(<1(04$351'( ='6'"C/6='&,B6 for >'$"/1!5$.G52W##,-LE5,6<&569"(M: %BcQP… ("'  %! %D,@/$H'61'(9I2='&,6B break<#d  public class SampleBreak2 { public static void main(String args[]) {  int i, j, product;  outer: for (i=1; i<=3; i++) { for (j=1; j<=3; j++) {  product = i*j;  if (j==3) break outer; System.out.println(i+" * "+j+" = "+product);  } }  System.out.println("Outside nested loops.");  }  }   



  %! .W##,-LE %BG52.'11'((,"!:(<1(0 %BcQPc





 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6





/& x ='&,B6!(6&(2'6@+30 :;"='&,B6 9%B I29"1'(1='4"5#='5,+1'( ='6'"C/6='&,6B DH'6F !5$0%&'0(M:<++7/ !(6&(2'6<++D'0#='5,+ !(6&(2'6<++#7/1 =' <#!(6&(2'6<++ ='R8=' x ='&,B6 %B:;"='&,6B C/6!(6&(2'6<++#7/1 ='7/ ='&,B6 if,

if..else

4(7/

switch

x ='&,B6if..else
x ='&,B6

if

if..else

&'0'(* %B.R2/"/$MCH 2'69"='&,B6

if

4(7/

.0%#,1?!(6&(2'61'( ='6'"#2'$#S61,+='&,6B  if..else if..else ..
x ='&,B6

switch

x ='&,B6 %B:;"='&,6B C/6!(6&(2'6<++ ='R8='7/ ='&,6B  4(7/for

while,

do..while

x ='&,B6while
x ='&,B6

for

x ='&,B6!(6&(2'6 6,8 405 %B1#H'@0'<#2@C2'6D2" &'0'(*"='0'9I2(H@01,":;" #,1?<++R2/"G52 IH" ='&,6B  switch /$MH>'$9"='&,6B  while  4(7/='&,B6 for/$MH>'$9"='&,6B forRSB6(%$1!(6&(2'69"#,1?"%8@H'!(6&(2'6<++R2/"

    

    





x ='&,B6 break. ='9424$35&A8"&351'( ='6'"C/6!(6&(2'6<++ ='R8='&H@"='&,6B  continue.C2'01'( ='6'"='&,B6 %B 4#7/>'$9"+#K/1!5$G:(A0 B 1'( ='R8=' 9"(/+DH/G:940H                        





 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

Related Documents

Chap 03
December 2019 7
Chap 03
November 2019 10
Chap 03
June 2020 5
Chap 03
May 2020 3
Chap 03 Solutions
November 2019 6
Alpha Chap 03
December 2019 11